/***************************************************************************
 创建者: 华磊
 开始时间: 2018.8.14
 copyright: (C) 华友高科
 修改说明: (每次有修改就添加一条，带有 修改人，修改时间，修改描述)
 example (1) hualei 2017.5.8 类的具体实现代码编写

 ***************************************************************************/
#include <QDateTime>
#include <QRegExp>
#include <QNetworkInterface>
#include <QNetworkAddressEntry>
#include <QSettings>

#include "XmlParse.h"
#include "md5check.h"
#include "measuretime.h"

#include "powermanager.h"
#include "robotmanager.h"
#include "messagelog.h"
#include "globalmanager.h"
#include "robotcontrol.h"
#include "commrobotiq.h"
#include "safewatchdog.h"
#include "authorityallowance.h"
#include "safetyfunction.h"
#include "hmigsoapqt.h"
#include "socketfleetadapter.h"
#include "modbusmanager.h"
#include "fleetservice.h"
#include "../ProgramEngine/programengine.h"
#include "robotengine.h"
#include "mccontrollerthread.h"

#define USER_INFO   "globalConfig/userInfo/userInfo.xml"
#define LICENSE_FILE_MAIN "globalConfig/license/mainLicense.xml"

#define FUNTION_IS_EMPTY qDebug("=====FUNTION_IS_EMPTY");
#define D_SET_ODOMETER_COVE_RATIO 0.1

extern PowerManager *p_powerManger;
extern RobotControl* robCtl;
extern HmiGsoapQt *commHmi;
extern SocketFleetAdapter *socketFleetAdapter;
extern ModbusManager *modbusManager;
extern FleetService *fleetService;


int PowerManager::getEmergencyDi(bool &emStop1,bool &emStop2)
{
    if( !robotManager  )
    {
        qDebug()<<"error,getEmergencyDi,!robotManager"<<robotManager;
        return -102;
    }

    if( false== robotManager->robotsMap.contains( robotId ) )
    {
        qDebug()<<"error,getEmergencyDi,false== robotManager->robotsMap.contains( robotId ),robotId"<<robotId;
        return -101;
    }


    RobotEngine* robotEngine= robotManager->robotsMap.value( robotId ,NULL );
    return robotEngine->getEmergencyDi(emStop1,emStop2);
}

int PowerManager::getServoOnDi(bool &servoOnDi)
{

    if( !robotManager  )
        return false;
    if( false== robotManager->robotsMap.contains( robotId ) )
        return false;

    RobotEngine* robotEngine= robotManager->robotsMap.value( robotId ,NULL );
    return robotEngine->getServoOnDi(servoOnDi);
}

unsigned short PowerManager::getDi_short(int shortIndex)
{
    if( !robotManager  )
        return false;
    if( false== robotManager->robotsMap.contains( robotId ) )
        return false;

    RobotEngine* robotEngine= robotManager->robotsMap.value( robotId ,NULL );
    return robotEngine->getDi_short(shortIndex);
}

unsigned short PowerManager::getDo_short(int shortIndex)
{
    if( !robotManager  )
        return false;
    if( false== robotManager->robotsMap.contains( robotId ) )
        return false;

    RobotEngine* robotEngine= robotManager->robotsMap.value( robotId ,NULL );
    return robotEngine->getDo_short(shortIndex);
}

int PowerManager::setDoVector(unsigned short doListIn, unsigned short doValidMask)
{
    if( !robotManager  )
        return false;
    if( false== robotManager->robotsMap.contains( robotId ) )
        return false;

    RobotEngine* robotEngine= robotManager->robotsMap.value( robotId ,NULL );
    return robotEngine->setDoVector(doListIn,doValidMask);
}

bool PowerManager::getCustomDiStatus(int index)
{
    if( !robotManager  )
        return false;
    if( false== robotManager->robotsMap.contains( robotId ) )
        return false;

    RobotEngine* robotEngine= robotManager->robotsMap.value( robotId ,NULL );
    return robotEngine->getCustomDiStatus(index);
}

bool PowerManager::getSystemDiStatus(int index)
{
    if( !robotManager  )
        return false;
    if( false== robotManager->robotsMap.contains( robotId ) )
        return false;

    RobotEngine* robotEngine= robotManager->robotsMap.value( robotId ,NULL );
    return robotEngine->getSystemDiStatus(index);

}

bool PowerManager::getSystemDoStatus(int index)
{
    if( !robotManager  )
        return false;
    if( false== robotManager->robotsMap.contains( robotId ) )
        return false;
    RobotEngine* robotEngine= robotManager->robotsMap.value( robotId ,NULL );
    return robotEngine->getSystemDoStatus(index);
}

bool PowerManager::getCustomDoStatus(int index)
{
    if( !robotManager  )
        return false;
    if( false== robotManager->robotsMap.contains( robotId ) )
        return false;
    RobotEngine* robotEngine= robotManager->robotsMap.value( robotId ,NULL );
    return robotEngine->getCustomDoStatus(index);
}

int PowerManager::setSystemDo(int index, bool val)
{
    if( !robotManager  )
        return false;

    if( false== robotManager->robotsMap.contains( robotId ) )
        return false;
    RobotEngine* robotEngine= robotManager->robotsMap.value( robotId ,NULL );
    return robotEngine->setSystemDo(index,val);
}

int PowerManager::setCustomDo(int index, bool val)
{
    if( !robotManager  )
        return false;
    if( false== robotManager->robotsMap.contains( robotId ) )
        return false;
    RobotEngine* robotEngine= robotManager->robotsMap.value( robotId ,NULL );
    return robotEngine->setCustomDo(index,val);
}

PowerManager::PowerManager(  )
{
    //---------初始化version线程锁--------
    pthread_mutexattr_init(&versionAttr);
    pthread_mutexattr_setprotocol(&versionAttr,PTHREAD_PRIO_INHERIT);
    pthread_mutex_init(&versionMutex,&versionAttr);

    versionInfo.componentName="PowerManager";
    versionInfo.componentVersion="V1.0";
    versionInfo.publishDate="2018.10.27";

    registerComponentVersion(versionInfo);
    robotId = 1;
    robotManager=NULL;
    messageLog=NULL;
    globalManager=NULL;
    enableRun[0]=true;
    enableRun[1]=true;
    enableRun[2]=true;
    enableRun[3]=true;

//#if D_IF_DEBUG
//    timeTest_1 = new MeasureTime( "lv1", 0, 1 ,  1 ) ;
//    timeTest_2 = new MeasureTime( "lv2", 0, 1 ,  100 ) ;
//    timeTest_3 = new MeasureTime( "lv3", 0, 1 ,  20 ) ;

//    timeTest_4 = new MeasureTime( "sf lv4", 0, 1 ,  100 ) ;
//    timeTest_5 = new MeasureTime( "eCat lv5", 0, 1 ,  100 ) ;
//    timeTest_6 = new MeasureTime( "pro lv6", 0, 1 ,  100 ) ;

    Init();

//    connect( &timer, SIGNAL(timeout()), this, SLOT( timeOutDo() ) );
//    timer.start( 10 );

}

PowerManager::~PowerManager()
{
    
}

int PowerManager::getLaserCameraBufferMoveConfigParameter(UserInfo userInfo, BufferMoveConfig &paraOut)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }
    return rob->programEngine->getLaserCameraBufferMoveConfigParameter(paraOut);
}

int PowerManager::setLaserCameraBufferMoveConfigParameter(UserInfo userInfo, BufferMoveConfig paraIn, int &returnFlag)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }
    returnFlag= rob->programEngine->setLaserCameraBufferMoveConfigParameter(paraIn);
    return returnFlag;
}

int PowerManager::getLaserTrackConfigParameter(UserInfo userInfo, LaserTrackConfig &paraOut)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }
    return rob->programEngine->getLaserTrackConfigParameter(paraOut);
}

int PowerManager::setLaserTrackConfigParameter(UserInfo userInfo, LaserTrackConfig paraIn, int &returnFlag)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }
    returnFlag= rob->programEngine->setLaserTrackConfigParameter(paraIn);
    return returnFlag;
}

int PowerManager::addCircle(UserInfo userInfo, int idIn, std::vector<double> posIn, std::vector<double> centerIn,
                            std::vector<double> normalIn, double vel, int turnsIn, int velTypeIn, int &returnFlag)
{
    ProgramEngine *tmpEngine=getProgramEngine(robotId);
    if( NULL==tmpEngine  )
    {
        returnFlag=0;
        return returnFlag;
    }

    returnFlag= tmpEngine->addCircle(idIn,posIn,centerIn,normalIn,vel,turnsIn,velTypeIn);
    return returnFlag;
}

int PowerManager::addProgramMoveCommand_hmi(UserInfo userInfo, vector<MoveParameter> tmpCommandVectorIn, int &returnFlag)
{

    ProgramEngine *tmpEngine=getProgramEngine(robotId);
    if( NULL==tmpEngine  )
    {
        returnFlag=0;
        return returnFlag;
    }

    returnFlag= tmpEngine->addProgramMoveCommand_hmi(tmpCommandVectorIn);
    return returnFlag;
}

int PowerManager::getPalletConditionInfo(UserInfo userInfo, std::vector<PalletMiddleInfo> &infoOut)
{
    int returnFlag;
    ProgramEngine *tmpEngine=getProgramEngine(robotId);
    if( NULL==tmpEngine  )
    {
        returnFlag=0;
        return returnFlag;
    }

    returnFlag= tmpEngine->getPalletConditionInfo(infoOut);
    return returnFlag;
}

int PowerManager::setPalletConditionInfo(UserInfo userInfo, StackInfo infoIn, int &returnFlag)
{
    ProgramEngine *tmpEngine=getProgramEngine(robotId);
    if( NULL==tmpEngine  )
    {
        returnFlag=0;
        return returnFlag;
    }

    returnFlag= tmpEngine->setPalletConditionInfo(infoIn);
    return returnFlag;
}

int PowerManager::getWeaveMotionConditionInfo(UserInfo userInfo, std::vector<WeaveMotionCondition> &infoOut)
{
    int returnFlag;
    ProgramEngine *tmpEngine=getProgramEngine(robotId);
    if( NULL==tmpEngine  )
    {
        returnFlag=0;
        return returnFlag;
    }

    returnFlag= tmpEngine->getWeaveMotionConditionInfo(infoOut);
    return returnFlag;
}

int PowerManager::setWeaveMotionConditionInfo(UserInfo userInfo, WeaveMotionCondition infoIn, int &returnFlag)
{

    ProgramEngine *tmpEngine=getProgramEngine(robotId);
    if( NULL==tmpEngine  )
    {
        returnFlag=0;
        return returnFlag;
    }

    returnFlag= tmpEngine->setWeaveMotionConditionInfo(infoIn);
    return returnFlag;
}

int PowerManager::getWeldDebugStatusInfo(UserInfo userInfo, WeldCraftStatusInfo &infoOut)
{
    int returnFlag;
    ProgramEngine *tmpEngine=getProgramEngine(robotId);
    if( NULL==tmpEngine  )
    {
        returnFlag=0;
        return returnFlag;
    }

    returnFlag= tmpEngine->getWeldDebugStatusInfo(infoOut);
    return returnFlag;
}

int PowerManager::weldDebugOperation(UserInfo userInfo, E_WELD_TEST typeIn, bool control, int &returnFlag)
{
    ProgramEngine *tmpEngine=getProgramEngine(robotId);
    if( NULL==tmpEngine  )
    {
        returnFlag=0;
        return returnFlag;
    }

    returnFlag= tmpEngine->weldDebugOperation(typeIn,control);
    return returnFlag;
}

int PowerManager::setWeldCollisionCheck(UserInfo userInfo, bool isCheck, int &returnFlag)
{
    ProgramEngine *tmpEngine=getProgramEngine(robotId);
    if( NULL==tmpEngine  )
    {
        returnFlag=0;
        return returnFlag;
    }

    returnFlag= tmpEngine->setWeldCollisionCheck(isCheck);
    return returnFlag;
}

int PowerManager::getTrigPosition(QQueue<PointPro> &trigPoseOut)
{
    int returnFlag=0;
    McControllerInterpreter *tmpMotionServer=isMotionServerInitialOk(robotId);
    if(NULL==tmpMotionServer)
    {
        return -1;
    }

    returnFlag=tmpMotionServer->getTrigPosition(trigPoseOut);
    return returnFlag;
}

int PowerManager::stopMotionTrig(int doIndex)
{
    int returnFlag=0;
    McControllerInterpreter *tmpMotionServer=isMotionServerInitialOk(robotId);
    if(NULL==tmpMotionServer)
    {
        return -1;
    }

    returnFlag=tmpMotionServer->stopMotionTrig(doIndex);
    return returnFlag;
}

int PowerManager::setMotionTrigPara(int doIndex, double trigPeriod)
{
    int returnFlag=0;
    McControllerInterpreter *tmpMotionServer=isMotionServerInitialOk(robotId);
    if(NULL==tmpMotionServer)
    {
        return -1;
    }

    returnFlag=tmpMotionServer->setMotionTrigPara(doIndex,trigPeriod);
    return returnFlag;
}

int PowerManager::setGravityVector(UserInfo userInfo, std::vector<double> gravityIn, int &returnFlag)
{
    returnFlag=0;
    McControllerInterpreter *tmpMotionServer=isMotionServerInitialOk(robotId);
    if(NULL==tmpMotionServer)
    {
        return -1;
    }

    returnFlag=tmpMotionServer->setGravityVector(gravityIn);
    return returnFlag;
}

int PowerManager::setToolMass(UserInfo userInfo, int toolIndex, double mass,
                              std::vector<double> center, int &returnFlag)
{
    returnFlag=0;
    McControllerInterpreter *tmpMotionServer=isMotionServerInitialOk(robotId);
    if(NULL==tmpMotionServer)
    {
        return -1;
    }

    returnFlag=tmpMotionServer->setToolMass(toolIndex,mass,center);
    return returnFlag;
}

int PowerManager::setDragControl(UserInfo userInfo, bool isOn, int &returnFlag)
{
    returnFlag=0;
    McControllerInterpreter *tmpMotionServer=isMotionServerInitialOk(robotId);
    if(NULL==tmpMotionServer)
    {
        return -1;
    }
    returnFlag=1;
    if(isOn)
    {
        return tmpMotionServer->setMotionServerModel(ENUM_MOTION_MODEL_DRAG);
    }
    return tmpMotionServer->setMotionServerModel(ENUM_MOTION_MODEL_TRAJECTORY_COMMAND_PROCESS);
}

int PowerManager::getRobotCoordinateConfig(UserInfo userInfo, RobotCoordinateAxisConfig &configOut)
{
    McControllerInterpreter *tmpMotionServer=isMotionServerInitialOk(robotId);
    if(NULL==tmpMotionServer)
    {
        return -1;
    }
    return tmpMotionServer->getRobotCoordinateConfig(configOut);

}

int PowerManager::setRobotCoordinateConfig(UserInfo userInfo, RobotCoordinateAxisConfig configIn, int &returnFlag)
{
    McControllerInterpreter *tmpMotionServer=isMotionServerInitialOk(robotId);
    if(NULL==tmpMotionServer)
    {
        return -1;
    }
    returnFlag= tmpMotionServer->setRobotCoordinateConfig(configIn);
    return returnFlag;
}

int PowerManager::getBatteryPeakConfig(UserInfo userInfo, BatteryPeakConfig &configOut)
{
    return globalManager->getBatteryPeakConfig(configOut);

}

int PowerManager::setBatteryPeakConfig(UserInfo userInfo, BatteryPeakConfig configIn, int &returnFlag)
{
    returnFlag= globalManager->setBatteryPeakConfig(configIn);
    return returnFlag;
}

int PowerManager::getReflectLaserFilterParameter(UserInfo userInfo, int index, LaserFilterParameter &paraOut)
{
    McControllerInterpreter *tmpMotionServer=isMotionServerInitialOk(robotId);
    if(NULL==tmpMotionServer)
    {
        return -1;
    }
    return tmpMotionServer->getReflectLaserFilterParameter(index,paraOut);
}

int PowerManager::setReflectLaserFilterParameter(UserInfo userInfo, int index, LaserFilterParameter paraIn, int &returnFlag)
{
    McControllerInterpreter *tmpMotionServer=isMotionServerInitialOk(robotId);
    if(NULL==tmpMotionServer)
    {
        return -1;
    }
    returnFlag= tmpMotionServer->setReflectLaserFilterParameter(index,paraIn);
    return returnFlag;
}

int PowerManager::getReflectCalculateCommonParameter(UserInfo userInfo, ReflectCommonDetectPara &paraOut)
{
    McControllerInterpreter *tmpMotionServer=isMotionServerInitialOk(robotId);
    if(NULL==tmpMotionServer)
    {
        return -1;
    }
    return tmpMotionServer->getReflectCalculateCommonParameter(paraOut);
}

int PowerManager::setReflectCalculateCommonParameter(UserInfo userInfo, ReflectCommonDetectPara paraIn, int &returnFlag)
{
    McControllerInterpreter *tmpMotionServer=isMotionServerInitialOk(robotId);
    if(NULL==tmpMotionServer)
    {
        return -1;
    }
    returnFlag= tmpMotionServer->setReflectCalculateCommonParameter(paraIn);
    return returnFlag;
}

int PowerManager::getAmclDebugInfo(UserInfo userInfo, AmclDebugInfo &debugInfoOut)
{
    McControllerInterpreter *tmpMotionServer=isMotionServerInitialOk(robotId);
    if(NULL==tmpMotionServer)
    {
        return -1;
    }
    return tmpMotionServer->getAmclDebugInfo(debugInfoOut);
}


int PowerManager::getVehicleMovingCaligrateInfo(UserInfo userInfo, VehicleMovingCaligrateInfo &infoOut)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }


    return rob->threadMotionEngine->mcControllerInterpreter->getVehicleMovingCaligrateInfo(infoOut);

}

int PowerManager::setCalibrateWheelDiameter(UserInfo userInfo, double idealMovedLength, double actualMovedLength, int &returnFlag)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }


    returnFlag= rob->threadMotionEngine->mcControllerInterpreter->setCalibrateWheelDiameter(idealMovedLength,actualMovedLength);
    return returnFlag;
}

int PowerManager::setCalibrateWheelDistance(UserInfo userInfo, double idealMovedAngle, double actualMovedAngle, int &returnFlag)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }


    returnFlag= rob->threadMotionEngine->mcControllerInterpreter->setCalibrateWheelDistance(idealMovedAngle,actualMovedAngle);
    return returnFlag;
}

int PowerManager::setEthernetIpAddress(UserInfo userInfo, string netNameIn, string ipIn, int &returnFlag)
{
    returnFlag= globalManager->setEthernetIpAddress(netNameIn,ipIn);
    return returnFlag;
}

int PowerManager::setAmclPara(UserInfo userInfo, AmclDebugPara paraIn, int &returnFlag)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }


    returnFlag= rob->threadMotionEngine->mcControllerInterpreter->setAmclPara(paraIn);
    return returnFlag;
}

int PowerManager::getAmclPara(UserInfo userInfo, AmclDebugPara &paraOut)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }


    return rob->threadMotionEngine->mcControllerInterpreter->getAmclPara(paraOut);

}

int PowerManager::setCurrentVehicleBorderId(UserInfo userInfo, int idIn, int &returnFlag)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }


    returnFlag= rob->threadMotionEngine->mcControllerInterpreter->setCurrentVehicleBorderId(idIn);
    return returnFlag;
}

int PowerManager::getCurrentVehicleBorderId(UserInfo userInfo, int &idOut)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }

    idOut= rob->threadMotionEngine->mcControllerInterpreter->getCurrentVehicleBorderId();
    return 1;
}

int PowerManager::setSefetyCheck(UserInfo userInfo, E_SAFETY_CHECK typeIn, int isEnable, int &returnFlag)
{
    returnFlag= safetyFunction->setSefetyCheck( typeIn, isEnable);
    return returnFlag;
}

int PowerManager::getSefetyCheck(UserInfo userInfo, E_SAFETY_CHECK typeIn, int &checkStatusReturn)
{
    return safetyFunction->getSefetyCheck( typeIn, checkStatusReturn);
}

int PowerManager::getRollerMechanismStatus(UserInfo userInfo, E_ROLLER_STATUS &statusOut)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }

    statusOut=rob->programEngine->getRollerMechanismStatus();
    return 1;

}

int PowerManager::setRollerMechanismConfig(UserInfo userInfo, RollerMechanismConfig configIn, int &returnFlag)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }

    returnFlag= rob->programEngine->setRollerMechanismConfig(configIn);
    return returnFlag;
}

int PowerManager::getRollerMechanismConfig(UserInfo userInfo, RollerMechanismConfig &configOut)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }


    return rob->programEngine->getRollerMechanismConfig(configOut);

}

int PowerManager::getLiftMechanismStatus(UserInfo userInfo, E_LIFT_STATUS &statusOut)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }


    statusOut= rob->programEngine->getLiftMechanismStatus();
    return 1;

}

int PowerManager::setLiftMechanismConfig(UserInfo userInfo, LiftMechanismConfig configIn, int &returnFlag)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }


    returnFlag= rob->programEngine->setLiftMechanismConfig(configIn);
    return returnFlag;
}

int PowerManager::getLiftMechanismConfig(UserInfo userInfo, LiftMechanismConfig &configOut)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }


    return rob->programEngine->getLiftMechanismConfig(configOut);

}

int PowerManager::getEncoderValue_belt(UserInfo userInfo, int beltIndexIn, int &encoderValueOut)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }


    int returnFlag= rob->threadMotionEngine->mcControllerInterpreter->getEncoderValue_belt(beltIndexIn,encoderValueOut);
    return returnFlag;
}

int PowerManager::getEncoderValue_vision(UserInfo userInfo, int visionIndexIn, int &encoderValueOut)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }


    int returnFlag= rob->threadMotionEngine->mcControllerInterpreter->getEncoderValue_vision(visionIndexIn,encoderValueOut);
    return returnFlag;
}

int PowerManager::forceConnectCamera(UserInfo userInfo, int visionIndex, int &returnFlag)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }

    returnFlag= rob->threadMotionEngine->mcControllerInterpreter->forceConnectCamera(visionIndex);
    return returnFlag;
}

int PowerManager::forceTrigCamera(UserInfo userInfo, int visionIndexIn, int isHighIn, int &returnFlag)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }


    returnFlag= rob->threadMotionEngine->mcControllerInterpreter->forceTrigCamera(visionIndexIn,isHighIn);
    return returnFlag;
}

int PowerManager::getCoupleControlInfo(UserInfo userInfo, std::vector<CoupleConfigParameter> &infoOut)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }


    int returnFlag= rob->threadMotionEngine->mcControllerInterpreter->getCoupleControlInfo(infoOut);
    return returnFlag;
}

int PowerManager::getAxisProperty(UserInfo userInfo, int axisId, AxisProperty_hmi &axisPropertyOut)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }


    int returnFlag= rob->threadMotionEngine->mcControllerInterpreter->getAxisProperty(axisId,axisPropertyOut);
    return returnFlag;
}

int PowerManager::setAxisProperty(UserInfo userInfo,int axisId, AxisProperty_hmi axisPropertyIn, int &returnFlag)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }


    returnFlag= rob->threadMotionEngine->mcControllerInterpreter->setAxisProperty(axisId,axisPropertyIn);
    return returnFlag;
}

int PowerManager::setCoupleRelativeDistanceMonitorEnable(UserInfo userInfo, int followAxisId, bool isEnableIn, int &returnFlag)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }


    returnFlag= rob->threadMotionEngine->mcControllerInterpreter->setCoupleRelativeDistanceMonitorEnable(followAxisId,isEnableIn);
    return returnFlag;
}

int PowerManager::setCoupleControlEnable(UserInfo userInfo, int followAxisId, bool isEnableIn, int &returnFlag)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }


    returnFlag= rob->threadMotionEngine->mcControllerInterpreter->setCoupleControlEnable(followAxisId,isEnableIn);
    return returnFlag;
}

int PowerManager::getImageStringFormImagePath(struct UserInfo userInfo,std::string imagePathIn,std::string &imageStrOut)
{
    return globalManager->getRobotImageStr(imagePathIn,imageStrOut);
}

int PowerManager::setWeldVirtualMode(UserInfo userInfo, bool isVirtualControlIn, int &returnFlag)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }


    returnFlag= rob->programEngine->setWeldVirtualMode(isVirtualControlIn);
    return returnFlag;
}

int PowerManager::getWeldIsVirtualStatus(UserInfo userInfo, int &returnFlag)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }

    returnFlag= rob->programEngine->getWeldIsVirtualStatus();
    return returnFlag;
}

int PowerManager::getAgvBorderInfo(UserInfo userInfo, VehicleBorderInfo &infoOut)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }

    return rob->threadMotionEngine->mcControllerInterpreter->getAgvBorderInfo(infoOut);
}

int PowerManager::setAgvBorderRectInfo(UserInfo userInfo, BorderRectInfo rectInfoIn, int &returnFlag)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }

    return rob->threadMotionEngine->mcControllerInterpreter->setAgvBorderRectInfo(rectInfoIn,returnFlag);
}

int PowerManager::getVehicleKinematicDimension(UserInfo userInfo, VehicleKinematicDimension &infoOut)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }

    return rob->threadMotionEngine->mcControllerInterpreter->getVehicleKinematicDimension(infoOut);
}

int PowerManager::setVehicleKinematicDimension(UserInfo userInfo, VehicleKinematicDimension infoIn, int &returnFlag)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }

    return rob->threadMotionEngine->mcControllerInterpreter->setVehicleKinematicDimension(infoIn,returnFlag);
}

int PowerManager::getLaserScanParameter(UserInfo userInfo, int laserId, LaserScanParameterHmi &infoOut)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }

    return rob->threadMotionEngine->mcControllerInterpreter->getLaserScanParameter(laserId,infoOut);
}

int PowerManager::setLaserScanParameter(UserInfo userInfo, int laserId, LaserScanParameterHmi infoIn, int &returnFlag)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }

    return rob->threadMotionEngine->mcControllerInterpreter->setLaserScanParameter(laserId,
                                                                                       infoIn,returnFlag);
}

int PowerManager::getVehicleJogControlParameter(UserInfo userInfo, VehicleJogControlParameter &infoOut)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }

    return rob->threadMotionEngine->mcControllerInterpreter->getVehicleJogControlParameter(infoOut);
}

int PowerManager::setVehicleJogControlParameter(UserInfo userInfo, VehicleJogControlParameter infoIn, int &returnFlag)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }

    return rob->threadMotionEngine->mcControllerInterpreter->setVehicleJogControlParameter(infoIn,returnFlag);
}

int PowerManager::getVehicleTrajectoryControlParameter(UserInfo userInfo, VehicleTrajectoryControlParameter &infoOut)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }

    return rob->threadMotionEngine->mcControllerInterpreter->getVehicleTrajectoryControlParameter(infoOut);
}

int PowerManager::setVehicleTrajectoryControlParameter(UserInfo userInfo, VehicleTrajectoryControlParameter infoIn,
                                                       int &returnFlag)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }

    return rob->threadMotionEngine->mcControllerInterpreter->setVehicleTrajectoryControlParameter(infoIn,returnFlag);
}

int PowerManager::getAgvSheftInfo(UserInfo userInfo, int sheftIndex,BorderRectInfo &infoOut)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }

    return rob->threadMotionEngine->mcControllerInterpreter->getAgvSheftInfo(sheftIndex,infoOut);
}

int PowerManager::setAgvSheftRectInfo(UserInfo userInfo,int sheftIndex, BorderRectInfo rectInfoIn, int &returnFlag)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }

    return rob->threadMotionEngine->mcControllerInterpreter->setAgvSheftRectInfo(sheftIndex,rectInfoIn,returnFlag);
}

int PowerManager::getVehiclePositionCalibrateInfo(UserInfo userInfo, VehiclePosition &infoOut)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }

    return rob->threadMotionEngine->mcControllerInterpreter->getVehiclePositionCalibrateInfo(infoOut);
}

int PowerManager::getLaserCameraConfigParameter(UserInfo userInfo, LaserCameraConfigParameter &infoOut)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }
    return rob->programEngine->getLaserCameraConfigParameter(infoOut);

}

int PowerManager::getLaserCameraStatus(UserInfo userInfo, LaserCameraStatusInfo &infoOut)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }
    return rob->programEngine->getLaserCameraStatus(infoOut);

}

int PowerManager::setLaserCameraConfigParameter(UserInfo userInfo, LaserCameraConfigParameter parameter, int &returnFlag)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }
    returnFlag=rob->programEngine->setLaserCameraConfigParameter(parameter);
    return returnFlag;
}

int PowerManager::reconnectLaserCamera(UserInfo userInfo, int &returnFlag)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }
    returnFlag=rob->programEngine->reconnectLaserCamera();
    return returnFlag;
}

int PowerManager::setLaserCameraWork(UserInfo userInfo, bool isWork, int &returnFlag)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }
    rob->programEngine->setLaserCameraShowLaser(isWork);
    returnFlag=rob->programEngine->setLaserCameraWork(isWork);
    return returnFlag;
}

int PowerManager::setLaserCameraJobId(UserInfo userInfo, int jobIdIn, int &returnFlag)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }
    returnFlag=rob->programEngine->setLaserCameraJobId(jobIdIn);
    return returnFlag;
}

int PowerManager::calculateLaserCameraFrame(UserInfo userInfo, std::vector<PointPro> tcpPointList,
                 std::vector<PointPro> cameraPointList, LaserCameraCalibrateResult &resultOut)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }

    return rob->threadMotionEngine->mcControllerInterpreter->calculateLaserCameraFrame(0,tcpPointList,
                                                   cameraPointList,resultOut);
}

int PowerManager::getLaserCameraFrameInfo(UserInfo userInfo, LaserCameraFrameInfo &infoOut)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }

    return rob->threadMotionEngine->mcControllerInterpreter->getLaserCameraFrameInfo(infoOut);
}

int PowerManager::returnRValue(int robotIdIn, bool &initialStatus,QVector<double> &regOut)
{
    if(false==robotManager->robotsMap.contains(robotIdIn))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }

    regOut= rob->programEngine->regData->returnRValue(initialStatus);
    return 1;

}

int PowerManager::setRegisterValue(UserInfo userInfo, int typeIn, int index, int subIndex, double valueIn)
{
    return setRegisterValue_inner(robotId,typeIn,index,subIndex,valueIn);
}

int PowerManager::setRegisterValue_inner(int robotIdIn,int typeIn, int index, int subIndex, double valueIn)
{
    if(false==robotManager->robotsMap.contains(robotIdIn))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    switch(typeIn)
    {
    case 0:
    {
        return rob->programEngine->regData->setRRegValue(index,valueIn);
        break;
    }
    case 1:
    {
        return globalManager->saveRegRValue(index,valueIn);
        break;
    }
    case 2:
    {
        return rob->programEngine->regData->setPrIJValue(index,subIndex,valueIn);
        break;
    }
    default:
    {
        qDebug()<<"failed,setRegisterValue unknown type"<<typeIn;
    }

    }

    return -1;
}

int PowerManager::setVisionTrigObjectLength(UserInfo userInfo, int visionIndex, double lengthIn)
{

    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }

    return rob->threadMotionEngine->mcControllerInterpreter->setVisionTrigObjectLength(visionIndex,lengthIn);

}

int PowerManager::getEncoderReciverDataList(UserInfo userInfo, std::vector<EncoderReceiverData> &dataListReturn)
{
    int returnFlag;
    if(false==robotManager->robotsMap.contains(robotId))
    {
        returnFlag=-1;
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        returnFlag=-1;
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        returnFlag=-1;
        return -1;
    }

    returnFlag=rob->threadMotionEngine->mcControllerInterpreter->getEncoderReceiverData(dataListReturn);

    return returnFlag;
}

int PowerManager::getBeltTrackDebugInfo(UserInfo userInfo, int index, BeltTrackDebugInfo &infoOut)
{
    int returnFlag;
    if(false==robotManager->robotsMap.contains(robotId))
    {
        returnFlag=-1;
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        returnFlag=-1;
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        returnFlag=-1;
        return -1;
    }
    int tmpKey=rob->threadMotionEngine->mcControllerInterpreter->getBeltTrackDebugInfo(index,infoOut);
    returnFlag=tmpKey;
    return tmpKey;
}

int PowerManager::getVisionTrackDebugInfo(UserInfo userInfo, int index, VisionTrackDebugInfo &infoOut)
{
    int returnFlag;
    if(false==robotManager->robotsMap.contains(robotId))
    {
        returnFlag=-1;
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        returnFlag=-1;
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        returnFlag=-1;
        return -1;
    }
    int tmpKey=rob->threadMotionEngine->mcControllerInterpreter->getVisionTrackDebugInfo(index,infoOut);
    returnFlag=tmpKey;
    return tmpKey;
}

int PowerManager::getWeldPropertyConfigList(UserInfo userInfo,std::vector<WeldProperty> &configListOut)
{
    qDebug()<<"PowerManager::getWeldPropertyList begin";
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
        {
                rob->getWeldProperty(configListOut);
        }
    }
    return 0;//必须有，代表通信成功
}

int PowerManager::getWeldConditionConfigList(struct UserInfo userInfo,std::vector<struct WeldCondition> &configListOut){
    qDebug()<<"PowerManager::getWeldConditionList begin";
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
        {
            rob->getWeldCondition(configListOut);
        }
    }
    return 0;//必须有，代表通信成功
}

int PowerManager::changeWeldConditionConfigList(struct UserInfo userInfo,struct WeldCondition configIn){
    qDebug()<<"PowerManager::changeWeldCondition begin";
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
        {
            //TODO修改配置
            rob->changeWeldConditionConfig(configIn);
        }
    }
    return 0;//必须有，代表通信成功
}

int PowerManager::changeWeldPropertyConfigList(struct UserInfo userInfo,WeldProperty configIn){
    qDebug()<<"PowerManager::changeWeldProperty begin";
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
        {
            //TODO修改配置
            rob->changeWeldPropertConfig(configIn);

        }
    }
    return 0;//必须有，代表通信成功
}

int PowerManager::getWeldSystemInfo(struct UserInfo userInfo, struct WeldSystemInfo &weldSystemInfo){
    qDebug()<<"PowerManager::getWeldSystemInfo begin";
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
        {
            //获取弧焊系统信息
            rob->getWeldSystemInfo(weldSystemInfo);
        }
    }
    return 0;//必须有，代表通信成功
}
int PowerManager::changeWeldSystemInfo(struct UserInfo userInfo, struct WeldSystemInfo configIn){
    qDebug()<<"PowerManager::changeWeldSystemInfo begin";
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
        {
            //TODO修改弧焊系统信息
            rob->changeWeldSystemInfo(configIn);
        }
    }
    return 0;//必须有，代表通信成功
}

int PowerManager::getVisionTrackConfigList(UserInfo userInfo, std::vector<VisionTrackConfig> &configListOut)
{
    int returnFlag;
    if(false==robotManager->robotsMap.contains(robotId))
    {
        returnFlag=-1;
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        returnFlag=-1;
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        returnFlag=-1;
        return -1;
    }
    int tmpKey=rob->threadMotionEngine->mcControllerInterpreter->getVisionTrackConfigList(configListOut);
    returnFlag=tmpKey;
    return tmpKey;
}

int PowerManager::getBeltTrackConfigList(UserInfo userInfo, std::vector<BeltTrackConfig> &configListOut)
{
    int returnFlag;
    if(false==robotManager->robotsMap.contains(robotId))
    {
        returnFlag=-1;
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        returnFlag=-1;
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        returnFlag=-1;
        return -1;
    }
    int tmpKey=rob->threadMotionEngine->mcControllerInterpreter->getBeltTrackConfigList(configListOut);
    returnFlag=tmpKey;
    return tmpKey;
}

int PowerManager::changeVisionTrackConfig(UserInfo userInfo, int id, VisionTrackConfig configIn, int &returnFlag)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        returnFlag=-1;
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        returnFlag=-1;
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        returnFlag=-1;
        return -1;
    }
    int tmpKey=rob->threadMotionEngine->mcControllerInterpreter->changeVisionTrackConfig(id,configIn,returnFlag);
    returnFlag=tmpKey;
    return tmpKey;
}

int PowerManager::changeBeltTrackConfig(UserInfo userInfo,int id, BeltTrackConfig configIn, int &returnFlag)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        returnFlag=-1;
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        returnFlag=-1;
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        returnFlag=-1;
        return -1;
    }
    int tmpKey=rob->threadMotionEngine->mcControllerInterpreter->changeBeltTrackConfig(id,configIn,returnFlag);
    returnFlag=tmpKey;
    return tmpKey;
}

int PowerManager::getMapPropertyInfo(UserInfo userInfo, string mapName, MapPropertyInfo &infoOut)
{
    RobotEngine* rob = robotManager->robotsMap.value(1, NULL);
    if(!rob)
    {
        qDebug()<<"Error: getMapPropertyInfo,机器人ID错误:"<<robotId;

        return 1;
    }

   return rob->threadMotionEngine->mcControllerInterpreter->getMapPropertyInfo(mapName,infoOut);
}

int PowerManager::getFleetMap(UserInfo userInfo, string mapName, string &mapInfoReturn)
{
    qDebug()<<"PowerManager::getFleetMap begin";
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
        {
            if(NULL!=fleetService)
            {
                if(""==mapName)
                {
//                    robotManager->robotsMap.value(robotId)->threadMotionEngine->
//                            mcControllerInterpreter->getCurrentMapName(mapName);
                    fleetService->getCurrentFleetMap(mapInfoReturn);
                }
                else
                {
                    fleetService->getFleetMap(mapName,mapInfoReturn);
                }
            }



        }

    }
    return 0;//必须有，代表通信成功
}

int PowerManager::writeFleetMap(UserInfo userInfo, std::string mapName, std::string &mapInfoIn)
{
    qDebug()<<"PowerManager::writeFleetMap begin";
//    qDebug()<<QString::fromStdString(mapInfoIn);
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
        {
            if(NULL!=fleetService)
            {
                if(""==mapName)
                {
                    robotManager->robotsMap.value(robotId)->threadMotionEngine->
                            mcControllerInterpreter->getCurrentMapName(mapName);
                }
                fleetService->writeFleetMap(mapName,mapInfoIn);
            }
        }

    }
    return 0;//必须有，代表通信成功
}

int PowerManager::calculateZeroOffset(struct UserInfo userInfo,std::vector<PointPro> pointList,
                                      struct AxisZeroOffsetInfo &returnInfo)
{
    int returnFlag;
    if(false==robotManager->robotsMap.contains(robotId))
    {
        returnFlag=-1;
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        returnFlag=-1;
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        returnFlag=-1;
        return -1;
    }
    int tmpKey=rob->threadMotionEngine->mcControllerInterpreter->calculateZeroOffset(pointList,returnInfo.zeroOffset
                                                                                     ,returnInfo.maxError);
    returnFlag=tmpKey;
    return tmpKey;
}

int PowerManager::calibrateRobotByOffset(UserInfo userInfo, std::vector<double> offsetIn, int &returnFlag)
{

    if(false==robotManager->robotsMap.contains(robotId))
    {
        returnFlag=-1;
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        returnFlag=-1;
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        returnFlag=-1;
        return -1;
    }
    int tmpKey=rob->threadMotionEngine->mcControllerInterpreter->calibrateRobotByOffset(offsetIn);
    returnFlag=tmpKey;
    return tmpKey;
}

int PowerManager::getPathMovingInfo_virtualLineControl(PathMovingInfo &infoOut)
{
    int returnFlag;
    if(false==robotManager->robotsMap.contains(1))
    {
        returnFlag=-1;
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( NULL==rob  )
    {
        returnFlag=-1;
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        returnFlag=-1;
        return -1;
    }
    int tmpKey=rob->threadMotionEngine->mcControllerInterpreter->getPathMovingInfo_virtualLineControl(infoOut);
    if(NULL!=fleetService)
    {
        infoOut.currentFloorId=fleetService->getCurrentFloorId();
    }
    returnFlag=tmpKey;
    return tmpKey;
}

int PowerManager::errorNoticeForFleetService()
{
    if(NULL!=fleetService)
    {
      return fleetService->errorNotice();
    }
    return -1;

}

int PowerManager::getAllReferenceMarks(UserInfo userInfo, std::vector<ReflectMarkInfo> &reflectMarksOut)
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }
    return rob->threadMotionEngine->mcControllerInterpreter->getAllReferenceMarks(reflectMarksOut);
}

int PowerManager::addReferenceMarkToMap(UserInfo userInfo, ReflectMarkInfo markIn, int &returnFlag)
{
    if(false==robotManager->robotsMap.contains(1))
    {
        returnFlag=-1;
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( NULL==rob  )
    {
        returnFlag=-1;
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        returnFlag=-1;
        return -1;
    }
    int tmpKey=rob->threadMotionEngine->mcControllerInterpreter->addReferenceMarkToMap(markIn);
    returnFlag=tmpKey;
    return tmpKey;
}

int PowerManager::saveReferenceMarkToFile(UserInfo userInfo, string fileNameIn, int &returnFlag)
{
    if(false==robotManager->robotsMap.contains(1))
    {
        returnFlag=-1;
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( NULL==rob  )
    {
        returnFlag=-1;
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        returnFlag=-1;
        return -1;
    }
    returnFlag= rob->threadMotionEngine->mcControllerInterpreter->saveReferenceMarkToFile(fileNameIn);
    return returnFlag;
}

int PowerManager::deleteReferenceMarkInMap(UserInfo userInfo, int uniqId, int &returnFlag)
{
    returnFlag=-1;
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }
    returnFlag= rob->threadMotionEngine->mcControllerInterpreter->deleteReferenceMarkInMap(uniqId);
    return returnFlag;
}

int PowerManager::getReflectDebugInfo(UserInfo userInfo, ReflectDebugInfo &matchDebugInfoOut)
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }
    return rob->threadMotionEngine->mcControllerInterpreter->getMatchDebugInfo_reflect(matchDebugInfoOut);
}

int PowerManager::setOriginalLaserFilterType(UserInfo userInfo, int typeIn, int &returnFlag)
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }
    return rob->threadMotionEngine->mcControllerInterpreter->setOriginalLaserFilterType((E_LASER_FILTER_TYPE)typeIn);
}

int PowerManager::getCurrentPathInformation(UserInfo userInfo, VehiclePosition &startPositionOut,
                                            QVector<VehiclePosition> &targetPositionOut, int &pointIndexOut,
                                            E_NAV_COMMAND &currentPathTypeOut, double &currentPathParameter1Out,
                                            double &currentPathParameter2Out)
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }
    return rob->threadMotionEngine->mcControllerInterpreter->getCurrentPathInformation(
                startPositionOut,targetPositionOut,pointIndexOut,currentPathTypeOut,
                  currentPathParameter1Out,currentPathParameter2Out);
}

int PowerManager::changeComputerTime(UserInfo userInfo, string timeIn, int &returnFlag)
{
    returnFlag= globalManager->changeComputerTime(timeIn);
    return 1;
}

int PowerManager::getSocketFleetCommandLog(std::queue<std::string> &fleetCommandLogOut)
{
//    return socketFleetAdapter->getFleetCommandLog(fleetCommandLogOut);
    if(NULL!=fleetService)
    {
        return fleetService->getFleetCommandLog(fleetCommandLogOut);
    }
    return 0;
}

int PowerManager::getModbusFleetCommandLog(std::queue<std::string> &fleetCommandLogOut)
{
    return modbusManager->getFleetCommandLog(fleetCommandLogOut);
}

int PowerManager::getEngineStatue()
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }
    return robotManager->robotsMap.value(1)->getEngineStatue();
}

int PowerManager::setEngineStatus_fleet(STOP_COMMAND_TYPE statusIn)
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }
    return robotManager->robotsMap.value(1)->setEngineStatus_fleet(statusIn);
}

int PowerManager::setRunningNumber_virtualLineControl(float numberIn)
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }
    return rob->threadMotionEngine->mcControllerInterpreter->setRunningNumber_virtualLineControl(numberIn);
}

int PowerManager::addMonitorDi_fleet(UserInfo userInfo, bool isOr, QVector<int> diIndex, QVector<int> diValue)
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }
    return robotManager->robotsMap.value(1)->addMonitorDi_fleet(isOr,diIndex,diValue);
}

int PowerManager::executeMoveRobotArm_run(UserInfo userInfo, const QVector<int> &lineList,
                                          const QVector<RobotArmMoveParameter> &pathListParaIn, int isLastPointMove)
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }
    return robotManager->robotsMap.value(1)->moveRobotArm_run(lineList,pathListParaIn,isLastPointMove);
}

int PowerManager::executeMultiPoint_run(UserInfo userInfo, const QVector<int> &lineList,
                             const QVector<LaserPathParameter> &laserPathListParaIn, int isLastPointMove)
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }
    return robotManager->robotsMap.value(1)->moveMultiPoint_run(lineList,laserPathListParaIn,isLastPointMove);
}

int PowerManager::executeMoveMaganeticInstruction(struct UserInfo userInfo,const MaganeticPathParameter paraIn)
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }
    return robotManager->robotsMap.value(1)->moveMagnetic_run(paraIn);
}

int PowerManager::executeChargeInstruction(UserInfo userInfo, const ChargeParameter &chargeParaIn)
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }
    return robotManager->robotsMap.value(1)->charging_run(chargeParaIn);
}

int PowerManager::executeLiftInstruction(UserInfo userInfo, const LiftParameter &liftParaIn)
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }
    return robotManager->robotsMap.value(1)->liftMechanism_run(liftParaIn);
}

int PowerManager::executeRollerInstruction(UserInfo userInfo, const RollerParameter &rollerParaIn)
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }
    return robotManager->robotsMap.value(1)->roller_run(rollerParaIn);
}


int PowerManager::loadMapAndSetOdometer(UserInfo userInfo, QString mapName, VehiclePosition position)
{
    RobotEngine* rob = robotManager->robotsMap.value(1, NULL);
    if(!rob)
    {
        qDebug()<<"Error: getBarriorDetectMode,机器人ID错误:"<<robotId;

        return 1;
    }

    if(NULL!=fleetService)
    {
        fleetService->loadMap(mapName.toStdString());
    }

   return rob->threadMotionEngine->mcControllerInterpreter->loadMapAndSetOdometer(mapName,position);

}

int PowerManager::setUltrasonicSensorDebugFlag(int debugFlagIn)
{
    return safetyFunction->setUltrasonicSensorDebugFlag(debugFlagIn);
}

int PowerManager::setGlobalManagerDebugFlag(int debugFlagIn)
{
    return globalManager->setDebugFlag(debugFlagIn);
}

int PowerManager::getQrcodeDebugInfo(UserInfo userInfo, QrcodeDebugInfo &infoOut)
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }
    return rob->threadMotionEngine->mcControllerInterpreter->getQrcodeDebugInfo(infoOut);
}

int PowerManager::getBarriorDetectMode(E_BARRIER_TETECT_MODE &modeOut)
{

    RobotEngine* rob = robotManager->robotsMap.value(1, NULL);
    if(!rob)
    {
        qDebug()<<"Error: getBarriorDetectMode,机器人ID错误:"<<robotId;

        return 1;
    }

   rob->threadMotionEngine->mcControllerInterpreter->getBarriorDetectMode(modeOut);
//   qDebug()<<"success:  PowerManager::getBarriorDetectMode, robotId="<<robotId;

   return 1;
}

int PowerManager::getBarrierRunMode(E_BARRIER_RUN_MODE &modeOut)
{
    RobotEngine* rob = robotManager->robotsMap.value(1, NULL);
    if(!rob)
    {
        qDebug()<<"Error: getBarriorDetectMode,机器人ID错误:"<<robotId;

        return 1;
    }

   modeOut=rob->threadMotionEngine->mcControllerInterpreter->getBarrierRunMode();
   return 1;
}

int PowerManager::playBarriorMusic(double barrierRatioIn)
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }
    return robotManager->robotsMap.value(1)->playBarriorMusic(barrierRatioIn);
}

int PowerManager::playMusic(QString musicFileName, int musicPlayTimes, int musicVolume)
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }
    return robotManager->robotsMap.value(1)->playMusic(musicFileName,musicPlayTimes,musicVolume);
}

int PowerManager::playSystemMusic(QString nameIn, int musicPlayTimes)
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }
    return robotManager->robotsMap.value(1)->playSystemMusic(nameIn,musicPlayTimes);
}

int PowerManager::playErrorMusic()
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }
    return robotManager->robotsMap.value(1)->playErrorMusic();
}

int PowerManager::restoreNormalMusic()
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }
    return robotManager->robotsMap.value(1)->restoreNormalMusic();
}

int PowerManager::getSafeCollisionInfo(UserInfo userInfo, int sensorType, CollisionPara &infoOut)
{
    //    qDebug()<<"PowerManager::getSafeCollisionInfo begin";
        RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
        if( rob  )
        {
            if((NULL!=rob->threadMotionEngine)
                    && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
            {

                   return  rob->threadMotionEngine->mcControllerInterpreter->getSafeCollisionInfo(sensorType,infoOut);

            }

        }
        return -1;
}

int PowerManager::setSafeCollisionInfo(UserInfo userInfo, int sensorType, CollisionPara infoIn, int &returnFlag)
{
    //    qDebug()<<"PowerManager::setSafeCollisionInfo begin";
        RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
        returnFlag=0;
        if( rob  )
        {
            if((NULL!=rob->threadMotionEngine)
                    && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
            {

                    return rob->threadMotionEngine->mcControllerInterpreter->setSafeCollisionInfo(sensorType,infoIn,returnFlag);
            }

        }
        return -1;
}

int PowerManager::getSerialPortListInfo(UserInfo userInfo, QStringList &ListOut)
{
    Q_UNUSED(userInfo);
    return globalManager->getSerialPortListInfo(ListOut);
}

int PowerManager::setUltrasonicSensor485Address(UserInfo userInfo, int origineAddressIn, int addressIn, int &returnFlag)
{
    return safetyFunction->setUltrasonicSensor485Address(origineAddressIn,addressIn);
}

int PowerManager::getRobotLogFileInfo(UserInfo userInfo, std::vector<Message> &messagesLogOut)
{
    Q_UNUSED(userInfo);
    return globalManager->getRobotLogFileInfo(robotId, messagesLogOut);
}

int PowerManager::addCommand(UserCommandData commandIn, int &returnFlag)
{
    //    qDebug()<<"PowerManager::addCommand begin";
        RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
        returnFlag = 0;
        if( rob  )
        {
            if((NULL!=rob->threadMotionEngine)
                    && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
            {

                    rob->addCommand(commandIn);
                    returnFlag = 1;
            }

        }
        return 0;//必须有，代表通信成功
}

int PowerManager::removeRobotProgramFile(UserInfo userInfo, string fileName, int &returnFlag)
{
    Q_UNUSED(userInfo);
    return globalManager->removeRobotProgramFile(robotId, fileName, returnFlag);
}

int PowerManager::readRobotProgramFile(UserInfo userInfo, string fileName, std::vector <std::string> &fileStringOut)
{
    Q_UNUSED(userInfo);
    return globalManager->readRobotProgramFile(robotId,fileName,fileStringOut);
}

int PowerManager::writeRobotProgramFile(UserInfo userInfo, string fileName, std::vector <std::string> fileStringIn, int &returnFlag)
{
    Q_UNUSED(userInfo);
    return globalManager->writeRobotProgramFile(robotId,fileName,fileStringIn,returnFlag);
}

int PowerManager::get_robot_program_files_strings(UserInfo userInfo, int languageId, RunningProgramInfo &infoOut)
{
    std::vector<std::string> fileNames;
    std::vector<int> runningLines;
    QVector<QVector<QString> > programStrings;
    get_robot_program_files_strings(userInfo,languageId,fileNames,runningLines,programStrings);
    //todo 获取的信息转换为infoOut
    infoOut.fileNames=fileNames;
    infoOut.runningLines=runningLines;
    infoOut.programStrings.resize(programStrings.size());
//    qDebug()<<"PowerManager,programStrings.size()="<<programStrings.size();

    for(int i=0;i<programStrings.size();i++)
    {
        for(int j=0;j<programStrings[i].size();j++)
        {
            infoOut.programStrings[i].push_back(programStrings[i][j].toStdString());
        }
    }

//    qDebug()<<"PowerManager,infoOut.programStrings.size="<<infoOut.programStrings.size();
    
    return 1;
}

int PowerManager::get_running_program_file_strings(UserInfo userInfo, int languageId, string fileName,
                                                   std::vector<string> &infoOut)
{
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( rob  )
    {
        if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
        {
            return 0;
        }
        QVector<QString> programStrings;
        rob->programEngine->get_running_program_file_strings_task(languageId, QString::fromStdString(fileName)
                                                             ,programStrings);
        infoOut.clear();
        for(int i=0;i<programStrings.size();i++)
        {
            infoOut.push_back(programStrings[i].toStdString());
        }
    }
    return 1;
}

int PowerManager::set_di_name_info(UserInfo userInfo, int indexIn, string nameIn, int &returnFlag)
{

    ProgramEngine *tmpEngine=getProgramEngine(robotId);
    if( NULL==tmpEngine  )
    {
        returnFlag=0;
        return returnFlag;
    }

    returnFlag= tmpEngine->set_IO_NameInfo( E_IoValueType_DI, indexIn, nameIn, returnFlag);
    return returnFlag;


}

int PowerManager::set_do_name_info(UserInfo userInfo, int indexIn, string nameIn, int &returnFlag)
{

    ProgramEngine *tmpEngine=getProgramEngine(robotId);
    if( NULL==tmpEngine  )
    {
        returnFlag=0;
        return returnFlag;
    }

    returnFlag= tmpEngine->set_IO_NameInfo( E_IoValueType_DO, indexIn, nameIn, returnFlag);
    return returnFlag;

}

int PowerManager::set_ai_name_info(UserInfo userInfo, int indexIn, string nameIn, int &returnFlag)
{

    ProgramEngine *tmpEngine=getProgramEngine(robotId);
    if( NULL==tmpEngine  )
    {
        returnFlag=0;
        return returnFlag;
    }

    returnFlag= tmpEngine->set_IO_NameInfo( E_IoValueType_AI, indexIn, nameIn, returnFlag);
    return returnFlag;
}

int PowerManager::set_ao_name_info(UserInfo userInfo, int indexIn, string nameIn, int &returnFlag)
{

    ProgramEngine *tmpEngine=getProgramEngine(robotId);
    if( NULL==tmpEngine  )
    {
        returnFlag=0;
        return returnFlag;
    }

    returnFlag= tmpEngine->set_IO_NameInfo( E_IoValueType_AO, indexIn, nameIn, returnFlag);
    return returnFlag;
}

int PowerManager::set_si_name_info(UserInfo userInfo, int indexIn, string nameIn, int &returnFlag)
{

    ProgramEngine *tmpEngine=getProgramEngine(robotId);
    if( NULL==tmpEngine  )
    {
        returnFlag=0;
        return returnFlag;
    }

    returnFlag= tmpEngine->set_IO_NameInfo( E_IoValueType_SI, indexIn, nameIn, returnFlag);
    return returnFlag;
}

int PowerManager::set_so_name_info(UserInfo userInfo, int indexIn, string nameIn, int &returnFlag)
{

    ProgramEngine *tmpEngine=getProgramEngine(robotId);
    if( NULL==tmpEngine  )
    {
        returnFlag=0;
        return returnFlag;
    }

    returnFlag= tmpEngine->set_IO_NameInfo( E_IoValueType_SO, indexIn, nameIn, returnFlag);
    return returnFlag;
}

int PowerManager::get_di_names_info(UserInfo userInfo, std::vector<string> &namesOut)
{
    Q_UNUSED(userInfo);
    return globalManager->get_di_name_info(robotId, namesOut);
}

int PowerManager::get_do_names_info(UserInfo userInfo, std::vector<string> &namesOut)
{
    Q_UNUSED(userInfo);
    return globalManager->get_do_name_info(robotId, namesOut);
}

int PowerManager::get_ai_names_info(UserInfo userInfo, std::vector<string> &namesOut)
{
    Q_UNUSED(userInfo);
    return globalManager->get_ai_name_info(robotId, namesOut);
}

int PowerManager::get_ao_names_info(UserInfo userInfo, std::vector<string> &namesOut)
{
    Q_UNUSED(userInfo);
    return globalManager->get_ao_name_info(robotId, namesOut);
}

int PowerManager::get_si_names_info(UserInfo userInfo, std::vector<string> &namesOut)
{
    Q_UNUSED(userInfo);
    return globalManager->get_si_name_info(robotId, namesOut);
}

int PowerManager::get_so_names_info(UserInfo userInfo, std::vector<string> &namesOut)
{
    Q_UNUSED(userInfo);
    return globalManager->get_so_name_info(robotId, namesOut);
}

int PowerManager::get_All_IO_NamesInfo(UserInfo userInfo, struct IOMapNamesInfo &nameOut)
{
    Q_UNUSED(userInfo);
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }
    return rob->programEngine->get_All_IO_NamesInfo( nameOut);
}

int PowerManager::setDefaultMapName(UserInfo userInfo, string fileNameIn, int &returnFlag)
{
    //    qDebug()<<"PowerManager::setDefaultMapName begin";
        RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
        if(fileNameIn.length()<=0)
        {
            returnFlag = -1;
            return 0;

        }
        if( rob  )
        {
            if((NULL!=rob->threadMotionEngine)
                    && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
            {

                    rob->threadMotionEngine->mcControllerInterpreter->setDefaultMapName(fileNameIn,returnFlag);
            }

        }
        return 0;//必须有，代表通信成功
}

int PowerManager::setBarrierRunMode(UserInfo userInfo, E_BARRIER_RUN_MODE modeIn, int &returnFlag)
{
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );

    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
        {
            returnFlag=1;
            rob->threadMotionEngine->mcControllerInterpreter->setBarrierRunMode(modeIn);
        }

    }
    return 0;//必须有，代表通信成功
}

int PowerManager::setCheckVehiclePosition_amcl(UserInfo userInfo, bool isCheck, int &returnFlag)
{
    //    qDebug()<<"PowerManager::setCheckVehiclePosition_amcl begin";
        RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
        if( rob  )
        {
            if((NULL!=rob->threadMotionEngine)
                    && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
            {

                    rob->threadMotionEngine->mcControllerInterpreter->setCheckVehiclePosition_amcl(isCheck);
            }

        }
        return 0;//必须有，代表通信成功
}

int PowerManager::moveToNavgationPoint(UserInfo userInfo, MovingToNavagationParameter parameterIn, int &returnFlag)
{
        qDebug()<<"PowerManager::moveToNavgationPoint begin";
        RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
        if( rob  )
        {
            if((NULL!=rob->threadMotionEngine)
                    && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
            {

                    rob->programEngine->moveToNavgationPoint(parameterIn,returnFlag);

            }

        }
        return 0;//必须有，代表通信成功
}

int PowerManager::setLaserIntensityFilterByType_visionMatch(UserInfo userInfo, int typeIn,int &returnFlag)
{
    //    qDebug()<<"PowerManager::setLaserIntensityFilterByType_visionMatch begin";
        RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
        if( rob  )
        {
            if((NULL!=rob->threadMotionEngine)
                    && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
            {

                    rob->threadMotionEngine->mcControllerInterpreter->setLaserIntensityFilterByType_visionMatch(typeIn);

            }

        }
        return 0;//必须有，代表通信成功
}

int PowerManager::getLicenseDayLefted()
{
    return authority->getLicenseDayLefted();
}

int PowerManager::getVehicleSafeSpeedRatio(UserInfo userInfo, double &ratioOut)
{
    //    qDebug()<<"PowerManager::getVehicleSafeSpeedRatio begin";
        RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
        if( rob  )
        {
            if((NULL!=rob->threadMotionEngine)
                    && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
            {

                    rob->threadMotionEngine->mcControllerInterpreter->getVehicleSafeSpeedRatio(ratioOut);

            }

        }
        return 0;//必须有，代表通信成功
}

int PowerManager::getBarrierProtectRatioOfMoving(UserInfo userInfo, double &ratioOut)
{
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
        {

                ratioOut=rob->threadMotionEngine->mcControllerInterpreter->getBarrierProtectRatioOfMoving();

        }

    }
    return 0;//必须有，代表通信成功
}

int PowerManager::getMatchDebugInfo_vmark(UserInfo userInfo, VisionMatchDebugInfo &infoOut)
{
    //    qDebug()<<"PowerManager::setLaserFilterByType_vmark begin";
        RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
        if( rob  )
        {
            if((NULL!=rob->threadMotionEngine)
                    && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
            {

                    rob->threadMotionEngine->mcControllerInterpreter->getMatchDebugInfo_vmark(infoOut);

            }

        }
        return 0;//必须有，代表通信成功
}

int PowerManager::setLaserFilterByType_vmark(UserInfo userInfo, int typeIn, int &returnFlag)
{
    //    qDebug()<<"PowerManager::setLaserFilterByType_vmark begin";
        RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
        if( rob  )
        {
            if((NULL!=rob->threadMotionEngine)
                    && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
            {

                    rob->threadMotionEngine->mcControllerInterpreter->setLaserIntensityFilterByType_visionMatch(typeIn);

            }

        }
        return 0;//必须有，代表通信成功
}

int PowerManager::setCurrentVMarkIndex(UserInfo userInfo, int indexIn,  int &returnFlag)
{
    //    qDebug()<<"PowerManager::setCurrentVMarkIndex begin";
        RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
        if( rob  )
        {
            if((NULL!=rob->threadMotionEngine)
                    && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
            {

                    rob->threadMotionEngine->mcControllerInterpreter->setCurrentVMarkIndex(indexIn);

            }

        }
        return 0;//必须有，代表通信成功
}

int PowerManager::setCurrentVMarkType(UserInfo userInfo, int currentVmarkTypeIn, int &returnFlag)
{
    //    qDebug()<<"PowerManager::setCurrentVMarkType begin";
        RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
        if( rob  )
        {
            if((NULL!=rob->threadMotionEngine)
                    && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
            {

                    rob->threadMotionEngine->mcControllerInterpreter->setCurrentVMarkType(currentVmarkTypeIn);
                    returnFlag=1;
            }
            else
            {
                returnFlag=0;
            }
        }
        else
        {
            returnFlag=0;
        }

        return 0;//必须有，代表通信成功
}

int PowerManager::getVmarkInfoList(UserInfo userInfo, std::vector<VMarkInfo> &vmarkInfoOut)
{
    //    qDebug()<<"PowerManager::getVmarkInfoList begin";
        RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
        if( rob  )
        {
            if((NULL!=rob->threadMotionEngine)
                    && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
            {
                QMap<int, VMarkInfo> tmp_vmarkInfo;
                VMarkInfo tmp_markInfo;
                rob->threadMotionEngine->mcControllerInterpreter->getVmarkInfoList(tmp_vmarkInfo);
                foreach(tmp_markInfo,tmp_vmarkInfo)
                {
                    vmarkInfoOut.push_back(tmp_markInfo);
                }

            }

        }
        return 0;//必须有，代表通信成功
}

int PowerManager::updateVMarkFile(UserInfo userInfo, string vmarkFileIn, int &returnFlag)
{
    //    qDebug()<<"PowerManager::getVehiclePosition_specified begin";
        RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
        if( rob  )
        {
            if((NULL!=rob->threadMotionEngine)
                    && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
            {

                    rob->threadMotionEngine->mcControllerInterpreter->updateVMarkFile(QString::fromStdString(vmarkFileIn));

            }

        }
        return 0;//必须有，代表通信成功
}

int PowerManager::createVMark(UserInfo userInfo, VMarkInfo infoIn, std::string vmarkFileIn, int &returnFlag)
{
    //    qDebug()<<"PowerManager::getVehiclePosition_specified begin";
        RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
        if( rob  )
        {
            if((NULL!=rob->threadMotionEngine)
                    && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
            {

                    rob->threadMotionEngine->mcControllerInterpreter->createVMark(infoIn,QString::fromStdString(vmarkFileIn));

            }

        }
        return 0;//必须有，代表通信成功
}

int PowerManager::getVMarkPositionInWorld(UserInfo userInfo,  PositionInfo_hmi &positionReturn)
{
    //    qDebug()<<"PowerManager::getVehiclePosition_specified begin";
        RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
        if( rob  )
        {
            if((NULL!=rob->threadMotionEngine)
                    && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
            {

                    rob->threadMotionEngine->mcControllerInterpreter->getVMarkPositionInWorld(positionReturn.position,
                                                                                              positionReturn.isUpdateSucess);
                    positionReturn.maxMatchError=-1;
                    positionReturn.matchScore=-1;

            }

        }
        return 0;//必须有，代表通信成功
}

int PowerManager::getTargetCommandVehiclePosition(UserInfo userInfo, VehiclePosition &targetOut)
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }
    int tmpPointIndex;
    robotManager->robotsMap.value(1)->threadMotionEngine->
            mcControllerInterpreter->getTargetCommandVehiclePosition(targetOut,tmpPointIndex);

    return 1;
}

int PowerManager::getTargetCommandVehiclePosition(VehiclePosition &targetOut, int &pointIndexOut)
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }

    robotManager->robotsMap.value(1)->threadMotionEngine->
            mcControllerInterpreter->getTargetCommandVehiclePosition(targetOut,pointIndexOut);

    return 1;
}

int PowerManager::getCarBorder(UserInfo userInfo, std::vector<struct VehiclePosition> &carBorderOut)
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }
    robotManager->robotsMap.value(1)->threadMotionEngine->
            mcControllerInterpreter->getCarBorder(carBorderOut);

    return 1;
}

int PowerManager::getCarBorderOffset(UserInfo userInfo, std::vector<struct VehiclePosition> &carBorderOffsetOut)
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }
    robotManager->robotsMap.value(1)->threadMotionEngine->
            mcControllerInterpreter->getCarBorderOffset(carBorderOffsetOut);

    return 1;
}

//int PowerManager::get_di_name_info(UserInfo userInfo, std::vector<string> &namesOut, int &returnFlag)
//{
//    return globalManager->get_di_name_info(robotId,namesOut, returnFlag);
//}

//int PowerManager::get_do_name_info(UserInfo userInfo, std::vector<string> &namesOut,int &returnFlag)
//{
//    return globalManager->get_do_name_info(robotId,namesOut, returnFlag);
//}

int PowerManager::getDpoint(UserInfo userInfo, string fileName, int pointIndex, DPoint &pointOut)
{
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( rob  )
    {
        if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
        {
            return 0;
        }

        return rob->programEngine->getDpoint( fileName,pointIndex, pointOut);
    }
    return 0;
}

int PowerManager::recordDpoint(struct UserInfo userInfo,std::string fileName,DPoint pointIn)
{
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( rob  )
    {
        if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
        {
            return 0;
        }

        int returnKey=rob->programEngine->recordDpoint( fileName, pointIn);
        //重新加载程序
        rob->openDefaultFile();
        return returnKey;
    }
    return 0;
}

int PowerManager::get_robot_running_program_files_info(UserInfo userInfo, std::vector<string> &fileNames,
                                                       std::vector<int> &runningLines)
{
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( rob  )
    {
        if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
        {
            return 0;
        }

        rob->programEngine->get_robot_running_program_files_info( fileNames, runningLines);
    }
    return 1;
}

int PowerManager::get_robot_program_files_strings(UserInfo userInfo,int languageId, std::vector<string> &fileNames,
                                                  std::vector<int> &runningLines, QVector<QVector<QString> > &programStrings)
{
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( rob  )
    {
        if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
        {
            return 0;
        }

        rob->programEngine->getProgramRunningInfo(languageId, fileNames, runningLines,programStrings);
    }
    return 1;
}

int PowerManager::getRobotProgramFileList(UserInfo userInfo, std::vector<string> &programFileListOut)
{
    return globalManager->getRobotProgramFileList(robotId,programFileListOut);
}

int PowerManager::getAllPointCloud_translated(UserInfo userInfo, std::vector<PointCloudData_3D> &pointCloudOut)
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    robotManager->robotsMap.value(1)->threadMotionEngine->
            mcControllerInterpreter->getAllPointCloud_translated(pointCloudOut);

    return 1;
}

int PowerManager::calibrateVehicle(UserInfo userInfo, double xOffset, double yOffset,
                                   double rOffset, int &returnFlag)
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    robotManager->robotsMap.value(1)->threadMotionEngine->
            mcControllerInterpreter->calibrateVehicle(xOffset,yOffset,rOffset);
    returnFlag=1;

    return 1;
}

int PowerManager::setDefaultProgramFile(UserInfo userInfo,std::string inProgramName,int &returnFlag)
{

    if(inProgramName.length()<=0)
    {
        returnFlag=3; //写入文件失败
        return returnFlag;
    }

    if(disOPeratorPermission(userInfo))
    {

    }
    else
    {
        //没有权限
        returnFlag = 1;
    }
    RobotEngine* robot=robotManager->robotsMap.value(robotId, NULL );
    if( robot && robot->programEngine && (robot->programEngine->getEngineStatue()) != ENUM_RUN )
    {
        int tmpReturn=robot->writeDefaultFileSetting(inProgramName );
        if(tmpReturn==1)
        {
            returnFlag=0;
        }
        else
        {
            returnFlag=3; //写入文件失败
        }
    }else{
        returnFlag = 2;
    }

   if( returnFlag==2 ){
//           QString msg=QObject::tr( "正在运动中 ! ");
       addMsg( ENUM_MSG_REMIND,  "PowerManager", "PowerManager",  6000,  robotId);
   }else   if( returnFlag==1 ){
//           QString msg=QObject::tr( "用户权限不足! ");
//           addMsg( ENUM_MSG_REMIND,  "PowerManager", "PowerManager",  6001,  robotId);
   }
   //else  执行操作

    return returnFlag;
}
int PowerManager::getUpdateControllerInfoLevel1(UserInfo userInfo, UpdateDataLv1 &updateDataLv1)
{

   return updateControllerInfoLevel1(userInfo,robotId,updateDataLv1);

}
int PowerManager::getMapNameList(UserInfo userInfo, std::vector<string> &mapNameListOut)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    robotManager->robotsMap.value(robotId)->threadMotionEngine->
            mcControllerInterpreter->getMapNameList(mapNameListOut);

    return 1;
}

int PowerManager::getVehicleSpeedFeedback(UserInfo userInfo, VehicleVelocity &velocityOut)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    robotManager->robotsMap.value(robotId)->threadMotionEngine->
            mcControllerInterpreter->getVehicleSpeedFeedback(velocityOut);

    return 1;
}

int PowerManager::resetCustomOdometer_positionManage(UserInfo userInfo, int &returnFlag)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    robotManager->robotsMap.value(robotId)->threadMotionEngine->
            mcControllerInterpreter->resetCustomOdometer_positionManage();

    return 1;
}

int PowerManager::getOdometer_positionManage(UserInfo userInfo, double &historyOdomOut, double &historyTimeOut,
                              double &customOdomOut, double &customeTimeOut)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    robotManager->robotsMap.value(robotId)->threadMotionEngine->
            mcControllerInterpreter->getOdometer_positionManage(historyOdomOut,historyTimeOut,customOdomOut,customeTimeOut);

    return 1;
}

int PowerManager::forceQuitProgram()
{
//    delete commHmi;
    return globalManager->forceQuitProgram();
}

int PowerManager::getBatteryInfo(BatteryInformation &batteryInfoOut)
{
    return globalManager->getBatteryInfo(batteryInfoOut);
}

int PowerManager::getPointCloudSafeStatus(std::vector<string> &sensorNameOut, std::vector<double> &sensorSafeRatioOut,
                                          bool &isCheckEnableOut)
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    robotManager->robotsMap.value(1)->threadMotionEngine->
            mcControllerInterpreter->getPointCloudSafeStatus(sensorNameOut,sensorSafeRatioOut,isCheckEnableOut);

    return 1;
}

int PowerManager::setPointCloudCheckEnable(UserInfo userInfo, bool isOn,int &returnFlag)
{
    return setPointCloudCheckEnable(isOn);
}

int PowerManager::setPointCloudCheckEnable(bool isOn)
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    robotManager->robotsMap.value(1)->threadMotionEngine->
            mcControllerInterpreter->setPointCloudCheckEnable(isOn);

    return 1;
}

int PowerManager::setUltrasonicSensorCheckEnable(bool isOn)
{
    return safetyFunction->setUltrasonicSensorCheckEnable(isOn);
}

int PowerManager::setUltrasonicSensorCheckEnable(UserInfo userInfo, bool isOn,int &returnFlag)
{
    return setUltrasonicSensorCheckEnable(isOn);
}

int PowerManager::getUltrasonicSensorSafeStatus(std::vector<double> &safeStatusOut, bool &isCheckEnableOut)
{
    return safetyFunction->getUltrasonicSensorSafeStatus(safeStatusOut,isCheckEnableOut);
}

int PowerManager::setUltrasonicPowerSupplyNoiseClass(int classIn)
{
    return safetyFunction->setUltrasonicPowerSupplyNoiseClass(classIn);
}

int PowerManager::setUltrasonicWork(int locationIn, bool isEnable)
{
    return safetyFunction->setUltrasonicWork(locationIn,isEnable);
}

int PowerManager::getUltrasonicDetectDistance(QVector<double> &distanceResultOut)
{
    return safetyFunction->getUltrasonicDetectDistance(distanceResultOut);
}

int PowerManager::getUltrasonicDetectDistance(std::vector<double> &distanceResultOut)
{
    QVector<double> distanceResult;
    safetyFunction->getUltrasonicDetectDistance(distanceResult);
    distanceResultOut=distanceResult.toStdVector();
    return 1;
}

int PowerManager::getUltrasonicSensorName(std::vector<string> &sensorNames)
{
    return safetyFunction->getUltrasonicSensorName(sensorNames);

}

int PowerManager::getUltrasonicDetectDistance(int locationIn, QVector<double> &distanceResultOut)
{
    return safetyFunction->getUltrasonicDetectDistance(locationIn,distanceResultOut);
}

int PowerManager::getUltrasonicStatus(QVector<int>  &deviceRequestCountOut)
{
    return safetyFunction->getUltrasonicStatus(deviceRequestCountOut);
}

int PowerManager::resetMaster(UserInfo userInfo, int &returnFlag)
{
    robCtl->resetMasterStatus();
    return 0;
}

int PowerManager::resetMasterTimeMeasure(UserInfo userInfo, int &returnFlag)
{
    robCtl->resetMasterTimeMeasure();
    return 0;
}

int PowerManager::addMessage(UserInfo userInfo, Message addMsgLog, int &returnFlag)
{
    return 0;//必须有，代表通信成功
}

int PowerManager::restartNfsService(UserInfo userInfo,int &returnFlag)
{
    if(disOPeratorPermission(userInfo))
    {
         if(1==globalManager->restartNfsService())
         {
             returnFlag=0;
         }
         else
         {
             returnFlag=-1;
         }

    }
    else
    {
        returnFlag=-2;
    }
    return 0;
}

int PowerManager::showMotionForm(int robotID)
{
    //    qDebug()<<"PowerManager::showMotionForm begin";
        RobotEngine* rob = robotManager->robotsMap.value( robotID, NULL );

        if( rob  )
        {
            if((NULL!=rob->threadMotionEngine)
                    && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
            {

                    rob->threadMotionEngine->mcControllerInterpreter->showMotionForm();

            }

        }
        return 0;//必须有，代表通信成功
}

int PowerManager::getRobotCount()
{
    return robotManager->robotsMap.size();
}

int PowerManager::initRobots()
{
    return robotManager->initRobots(readStartType());
}

int PowerManager::getToolCoordinateInformation(UserInfo userInfo, int robotID, std::vector<HmiToolCoordinateInformation> &toolList)
{
    QVector<ToolCoordinateInfo> tmp = robotManager->robotsMap.value(robotID, NULL )->
            threadMotionEngine->mcControllerInterpreter->getToolCoordinateList();
    int tmpSize = tmp.size();
    toolList.resize(tmpSize);
    for(int i=0; i<tmpSize; i++)
    {
        toolList[i].index = tmp[i].index;
        toolList[i].error = tmp[i].error;
        toolList[i].method = tmp[i].method;
        toolList[i].pointList = tmp[i].pointList.toStdVector();
        toolList[i].xyzwpr = tmp[i].xyzwpr.toStdVector();
        toolList[i].mass = tmp[i].mass;
        toolList[i].massCenter = tmp[i].massCenter.toStdVector();
        toolList[i].name = tmp[i].name;
    }
    return 1;
}

int PowerManager::getUserCoordinateInformation(UserInfo userInfo, int robotID, std::vector<HmiUserCoordinateInformation> &userList)
{
    QVector<UserCoordinateInfo> tmp = robotManager->robotsMap.value(robotID, NULL )->
            threadMotionEngine->mcControllerInterpreter->getUserCoordinateList();
    int tmpSize = tmp.size();
    userList.resize(tmpSize);
    for(int i=0; i<tmpSize; i++)
    {
        userList[i].index = tmp[i].index;
        userList[i].method = tmp[i].method;
        userList[i].pointList = tmp[i].pointList.toStdVector();
        userList[i].xyzwpr = tmp[i].xyzwpr.toStdVector();
        userList[i].name = tmp[i].name;
    }
    return 1;
}

int PowerManager::calculateUserCoordinate(UserInfo userInfo, int robotID, HmiUserCoordinateInformation sendUserCoordinate,
                                          HmiUserCoordinateInformation &resultUserCoordinate)
{
    UserCoordinateInfo userCoInfo;
    userCoInfo.index = sendUserCoordinate.index;
    userCoInfo.method = sendUserCoordinate.method;
    userCoInfo.pointList = QVector<PointPro>::fromStdVector(sendUserCoordinate.pointList);
    userCoInfo.xyzwpr = QVector<double>::fromStdVector(sendUserCoordinate.xyzwpr);
    userCoInfo.name =sendUserCoordinate.name;
    robotManager->robotsMap.value(robotID, NULL )->threadMotionEngine->mcControllerInterpreter->setUserCoordinate(userCoInfo);
    resultUserCoordinate.index = userCoInfo.index;
    resultUserCoordinate.method = userCoInfo.method;
    resultUserCoordinate.pointList = sendUserCoordinate.pointList;
    resultUserCoordinate.xyzwpr = userCoInfo.xyzwpr.toStdVector();
    resultUserCoordinate.name = userCoInfo.name;
//    qDebug()<<"calculateUserCoordinate====index"<<sendUserCoordinate.index<<userCoInfo.index << resultUserCoordinate.index;
//    qDebug()<<"calculateUserCoordinate====method"<<sendUserCoordinate.method<<userCoInfo.method << resultUserCoordinate.method;
    return 0;
}

int PowerManager::calculateToolCoordinate(UserInfo userInfo, int robotID, HmiToolCoordinateInformation sendToolCoordinate, HmiToolCoordinateInformation &resultToolCoordinate)
{
    ToolCoordinateInfo toolInfo;
    toolInfo.index = sendToolCoordinate.index;
    toolInfo.method = sendToolCoordinate.method;
    toolInfo.name = sendToolCoordinate.name;
    toolInfo.pointList = QVector<PointPro>::fromStdVector(sendToolCoordinate.pointList);
    toolInfo.xyzwpr = QVector<double>::fromStdVector(sendToolCoordinate.xyzwpr);
    robotManager->robotsMap.value(robotID, NULL )->threadMotionEngine->mcControllerInterpreter->
            setToolCoordinate(toolInfo);
    resultToolCoordinate.index = toolInfo.index;
    resultToolCoordinate.method = toolInfo.method;
    resultToolCoordinate.pointList = sendToolCoordinate.pointList;//toolInfo
    resultToolCoordinate.xyzwpr = toolInfo.xyzwpr.toStdVector();
    resultToolCoordinate.error = toolInfo.error;
    resultToolCoordinate.name = toolInfo.name;
//    qDebug()<<"calculateToolCoordinate====index"<<sendToolCoordinate.index<<toolInfo.index << resultToolCoordinate.index;
//    qDebug()<<"calculateToolCoordinate====method"<<sendToolCoordinate.method<<toolInfo.method << resultToolCoordinate.method;
    return 0;
}

int PowerManager::getVrepRadianToEncoder(int robID, int axis, float &radianVec)
{//需要正确设置轴的类型，才能正确转换。
    if(false==robotManager->robotsMap.contains(robID))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robID, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }
    return robotManager->robotsMap.value(robID)->threadMotionEngine
            ->mcControllerInterpreter->getVrepRadianToEncoder(axis,radianVec);
}

float PowerManager::getVrepEncoderToRadian(int robID, int axis, const int &encoderVec)
{//需要正确设置轴的类型，才能正确转换。
    if(false==robotManager->robotsMap.contains(robID))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robID, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }
    return robotManager->robotsMap.value(robID)->threadMotionEngine
            ->mcControllerInterpreter->getVrepEncoderToRadian(axis,encoderVec);
}

int PowerManager::initialServoParameter(int robID)
{
//    if(false==robotManager->robotsMap.contains(robID))
//    {
//        addMsg( ENUM_MSG_ERROR,  "PowerManager", "PowerManager",  60000,  robotId);
//        return -1;
//    }
//    RobotEngine* rob = robotManager->robotsMap.value( robID, NULL );
//    if( NULL==rob  )
//    {
//        addMsg( ENUM_MSG_ERROR,  "PowerManager", "PowerManager",  60001,  robotId);
//        return -2;
//    }

    while(false==robotManager->robotsMap.contains(robID))
    {
        usleep(100);
//        qDebug()<<"warnning,,,,,false==robotManager->robotsMap.contains(robID)";
    }

    while(NULL==robotManager->robotsMap.value( robID, NULL ))
    {
        usleep(100);
//        qDebug()<<"warnning,,,,,NULL==robotManager->robotsMap.value( robID, NULL )";
    }

//    if(NULL==robotManager->robotsMap.value(robID)->threadMotionEngine)
//    {
//        qDebug()<<"error,,,,,initialServoParameter,NULL==threadMotionEngine";
//        return -1;
//    }
    while(NULL==robotManager->robotsMap.value(robID)->threadMotionEngine)
    {
        usleep(100);
//        qDebug()<<"warnning,,,,,initialServoParameter,NULL==threadMotionEngine";
    }
    return robotManager->robotsMap.value(robID)->threadMotionEngine->initialServoParameter();
}

int PowerManager::setMotorControlMode(int robID,int axisId, E_MOTOR_CONTROL_MODE modeIn)
{
    return robotManager->robotsMap.value(robID)->threadMotionEngine->setMotorControlMode(axisId,modeIn);
}

int PowerManager::algorithmFunctioncall(int robID, QVector<bool> servoOnStatus, QVector<MotorData> motorFeedback,
                                        QVector<MotorData> &motorCommandOut,
                                        int &returnMutexFlag)
{
    motorCommandOut.clear();
    if(NULL!=robotManager->robotsMap.value(robID)->threadMotionEngine)
    {
         return robotManager->robotsMap.value(robID)->threadMotionEngine->algorithmFunctioncall(servoOnStatus,
                                                                                motorFeedback,motorCommandOut,returnMutexFlag);
    }
    else
    {
        return -1;
    }

}

int PowerManager::getMotorEncoderPulsePerRound(int robID, QVector<double> &pulseOut)
{
    if(NULL!=robotManager->robotsMap.value(robID)->threadMotionEngine)
    {
         return robotManager->robotsMap.value(robID)->threadMotionEngine->mcControllerInterpreter->getMotorEncoderPulsePerRound(pulseOut);
    }
    else
    {
        qDebug()<<"failed,,,getMotorEncoderPulsePerRound1";
        return -1;
    }
    return 1;
}

bool PowerManager::getCurrentRobotId(int &robotIdOut)
{
    if(true==robotManager->robotsMap.contains(robotId))
    {
        robotIdOut=robotId;
        return true;
    }
    return false;
}

EN_CONTROL_TYPE PowerManager::getRunModel()
{
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
        {
                return rob->programEngine->getRunModel();
        }

    }
    return ENUM_CONTROL_END;

}

int PowerManager::startGoZero_forUser(int robID, int axisId)
{
    return robotManager->robotsMap.value(robID)->threadMotionEngine->
            mcControllerInterpreter->startGoZero_forUser(axisId);
}

int PowerManager::startGoZero_forUser(int robID)
{
    return robotManager->robotsMap.value(robID)->threadMotionEngine->
            mcControllerInterpreter->startGoZero_forUser();
}

int PowerManager::haltGoZero_forUser(int robID)
{
    return robotManager->robotsMap.value(robID)->threadMotionEngine->
            mcControllerInterpreter->haltGoZero_forUser();
}

//int PowerManager::feedRosWatchDog(UserInfo userInfo, int flagIn, int &returnFlag)
//{
//    return watchDog->feedDog();

//}

//int PowerManager::addMessage(UserInfo userInfo,Message addMsgLog,int &returnFlag)
//{
//    MessageLog::getInstance()->addMessage(addMsgLog);
//    returnFlag=1;
//    return 0;
//}

int PowerManager::getSdo(UserInfo userInfo, int robID, int axis, int rObIndex, int rObSubIndex, LONG64 &rData)
{
    int lengthReturn;
    if(1==robCtl->getSdo(robID,axis,rObIndex,rObSubIndex,rData,lengthReturn))
    {

        return 0;
    }
    else
    {
        return -1;
    }
    return -1;
}

int PowerManager::getSdoByNodeId(UserInfo userInfo, int nodeId, int rObIndex, int rObSubIndex, int64_t &rData)
{
    int lengthReturn;
    if(1==robCtl->getSdoByNodeId(nodeId,rObIndex,rObSubIndex,rData,lengthReturn))
    {

        return 0;
    }
    else
    {
        return -1;
    }
    return -1;
}

int PowerManager::getSdoByAlias(UserInfo userInfo, int alias, int rObIndex, int rObSubIndex, int64_t &rData)
{
    int lengthReturn;
    if(1==robCtl->getSdoByAlias(alias,rObIndex,rObSubIndex,rData,lengthReturn))
    {

        return 0;
    }
    else
    {
        return -1;
    }
    return -1;
}

int PowerManager::setSdo(UserInfo userInfo, int robID, int axis, int wObIndex,
                         int wObSubIndex, int64_t wData, int wDataLen, int &returnFlag)
{
    returnFlag=0;
    if(1==robCtl->setSdo(robID,axis,wObIndex,wObSubIndex,wData,wDataLen))
    {
        returnFlag=1;
        return 0;//必须为０，gosoap 用
    }
    else
    {
        returnFlag=-1;
        return -1;
    }
    return -1;
}

int PowerManager::setSdoByNodeId(UserInfo userInfo, int nodeId, int wObIndex, int wObSubIndex, int64_t wData, int wDataLen, int &returnFlag)
{
    returnFlag=0;
    if(1==robCtl->setSdoByNodeId(nodeId,wObIndex,wObSubIndex,wData,wDataLen))
    {
        returnFlag=1;
        return 0;//必须为０，gosoap 用
    }
    else
    {
        returnFlag=-1;
        return -1;
    }
    return -1;
}

int PowerManager::setSdoByAlias(UserInfo userInfo, int alias, int wObIndex, int wObSubIndex, int64_t wData, int wDataLen, int &returnFlag)
{
    returnFlag=0;
    if(1==robCtl->setSdoByAlias(alias,wObIndex,wObSubIndex,wData,wDataLen))
    {
        returnFlag=1;
        return 0;//必须为０，gosoap 用
    }
    else
    {
        returnFlag=-1;
        return -1;
    }
    return -1;
}

void PowerManager::robotiq_clamp_move(short pos, short sp, short tq)
{
    return ctlRobotiq->move(pos,sp,tq);
}

int PowerManager::connectRobotiq()
{
    return ctlRobotiq->connectRobotiq();

}

int PowerManager::getEthercatDebugInfo(UserInfo userInfo, EthercatDebugInfo &debugInfo)
{
    if(1==robCtl->getEthercatDebugInfo(debugInfo))
    {
        return 0;
    }
    else
    {
        return -1;
    }
}

int PowerManager::getCanDebugInfo(UserInfo userInfo, EthercatDebugInfo &debugInfo)
{
    if(1==robCtl->getCanDebugInfo(debugInfo))
    {
        return 0;
    }
    else
    {
        return -1;
    }
}

int PowerManager::getModbusDebugInfo(UserInfo userInfo, bool isModbusRtu, int busIndex, EthercatDebugInfo &debugInfo)
{
    if(1==robCtl->getModbusDebugInfo(isModbusRtu,busIndex,debugInfo))
    {
        return 0;
    }
    else
    {
        return -1;
    }
}

int PowerManager::allowSingleAxisJog(UserInfo userInfo, bool enable, int &returnFlag)
{
    returnFlag=0;
    return robotManager->robotsMap.value(robotId)->threadMotionEngine->
            mcControllerInterpreter->allowSingleAxisJog(enable);
}

int PowerManager::setEthercatMotorDcUserMode(UserInfo userInfo, int robID, int &returnFlag)
{
    returnFlag=0;
    if(1==robCtl->setEthercatMotorDcUserMode(robotId))
    {
        returnFlag=0;
        return 0;
    }
    else
    {
        returnFlag=-1;
        return -1;
    }
}

int PowerManager::setEthercatDeviceAlias(UserInfo userInfo, int node, unsigned short alias, int &returnFlag)
{
    returnFlag=0;
    return robCtl->setAlias(node,alias);
}

int PowerManager::getEthercatSlavesInformation(UserInfo userInfo, std::vector<EcatBusDevInfo_gsoap> &slavesInfo)
{
    return robCtl->getEthercatSlavesInformation(slavesInfo);
}

int PowerManager::getMotionServerDebugInfo(UserInfo userInfo,MotionDebugInfo &infoOut)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }
    return robotManager->robotsMap.value(robotId)->threadMotionEngine->
            mcControllerInterpreter->getDebugInfo(infoOut);

}

int PowerManager::getVirtualLineControlDebugInfo(UserInfo userInfo, VirtualLineDebugInfo &infoOut)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }
    return robotManager->robotsMap.value(robotId)->threadMotionEngine->
            mcControllerInterpreter->getVirtuleLineDebugInfo(infoOut);

}

int PowerManager::getProgramEngineDebugInfoList(UserInfo userInfo,
                                           std::vector<ProgramEngineDebugInfo> &infoListOut)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }
    return robotManager->robotsMap.value(robotId)->programEngine->getDebugInfoList(infoListOut);
}

int PowerManager::getProgramEngineDebugInfo(UserInfo userInfo,ProgramEngineDebugInfo &infoOut)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }
    return robotManager->robotsMap.value(robotId)->programEngine->getDebugInfo(infoOut);
}

int PowerManager::getTaskInfo(UserInfo userInfo, TaskManagerInfo &taskManagerInfo)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }
    return robotManager->robotsMap.value(robotId)->programEngine->getTaskInfo(taskManagerInfo);
}

int PowerManager::getAllTaskInfo(UserInfo userInfo
                                 ,std::vector<TaskManagerInfo> &taskManagerInfo)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }

    taskManagerInfo.clear();

    RobotInfo* robInfo;
    TaskManagerInfo tmpTaskInfo;
    foreach ( robInfo, robotManager->robotsInfoMap )
    {
        robotManager->robotsMap.value(robInfo->robotId)->programEngine->getTaskInfo(tmpTaskInfo);
        tmpTaskInfo.robotName=robInfo->robotName.toStdString();
        taskManagerInfo.push_back(tmpTaskInfo);
    }

    return 1;
}

int PowerManager::setEnableRun(int index, bool enable)
{
    if(index>=0 && index<4)
    {
        enableRun[index]=enable;
        return 1;
    }
    return -1;
}

bool PowerManager::isEthercatDeviceInitialOk()
{
    return robCtl->isInitialOk();
}

bool PowerManager::isCurrentRobotAxisZeroOk()
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return false;
    }
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( NULL==rob  )
    {
        return false;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return false;
    }
    return rob->threadMotionEngine->mcControllerInterpreter->isAxisZeroOk();

}

int PowerManager::clearMotorBatteryError(UserInfo userInfo, int &returnFlag)
{
    if(disOPeratorPermission(userInfo))
    {
         if(true==robCtl->clearMotorBatteryError(robotId))
         {
            returnFlag=1;

         }
         else
         {
            returnFlag=-1;
         }

    }
    else
    {
        returnFlag=-2;
    }

    return returnFlag;
}

int PowerManager::clearMotorBatteryErrorByAxis(UserInfo userInfo, int axisId, int &returnFlag)
{
    if(disOPeratorPermission(userInfo))
    {
         if(true==robCtl->clearMotorBatteryErrorByAxis(robotId,axisId))
         {
            returnFlag=1;

         }
         else
         {
            returnFlag=-1;
         }

    }
    else
    {
        returnFlag=-2;
    }

    return returnFlag;
}

int PowerManager::getBackupFileList(UserInfo userInfo,int pathType, vector<string> &fileList)
{
    qDebug()<<"PowerManager::getBackupFileList start";
    if(disOPeratorPermission(userInfo))
    {
        QVector<QString> qfileList;

         if(1==globalManager->getFileList(pathType,qfileList))
         {
             fileList.resize(qfileList.size());
             for(int i=0;i<qfileList.size();i++)
             {
                 fileList[i]=qfileList[i].toStdString();
             }

         }
         else
         {

         }

    }
    else
    {

    }
    qDebug()<<"PowerManager::getBackupFileList end";
    return 0;

}

int PowerManager::backupFile(UserInfo userInfo, int backUpType, int diskType,
                             string fileName, int robotId, int &returnFlag)
{
    if(disOPeratorPermission(userInfo))
    {
         if(1==globalManager->backupFile(backUpType,diskType,QString::fromStdString(fileName),robotId))
         {
             returnFlag=0;
         }
         else
         {
             returnFlag=-1;
         }

    }
    else
    {
        returnFlag=-2;
    }
    return 0;
}

int PowerManager::restoreFile(UserInfo userInfo, int backUpType, int diskType,
                              string fileName, int robotId, int &returnFlag)
{
    if(disOPeratorPermission(userInfo))
    {
         if(1==globalManager->restoreFile(backUpType,diskType,QString::fromStdString(fileName),robotId))
         {
             returnFlag=0;
         }
         else
         {
             returnFlag=-1;
         }

    }
    else
    {
        returnFlag=-2;
    }
    return 0;
}

int PowerManager::getWheelData(UserInfo userInfo, int robotIdIn, vector<double> &wheelMoveSpeed,
                               vector<double> &wheelPathLength)
{
    if(false==robotManager->robotsMap.contains(robotIdIn))
    {
        return -1;
    }
    robotManager->robotsMap.value(robotIdIn)->threadMotionEngine->
            mcControllerInterpreter->getWheelData(wheelMoveSpeed,wheelPathLength);

    return 1;
}

int PowerManager::getOdometer(struct UserInfo userInfo,int robotIdIn,VehicleVelocity &vehicleVelFeedbackOut,
                              VehiclePosition &vehiclePositionFeedbackOut)
{
    if(false==robotManager->robotsMap.contains(robotIdIn))
    {
        return -1;
    }
    robotManager->robotsMap.value(robotIdIn)->threadMotionEngine->
            mcControllerInterpreter->getOdometer(vehicleVelFeedbackOut,vehiclePositionFeedbackOut);

    return 1;
}

int PowerManager::vehicleAuto(UserInfo userInfo, int robotIdIn, double xMove, double yMove, double rotate)
{


    if(false==robotManager->robotsMap.contains(robotIdIn))
    {
        return -1;
    }
    watchDog->startDog();
    robotManager->robotsMap.value(robotIdIn)->threadMotionEngine->
            mcControllerInterpreter->vehicleAuto(xMove,yMove,rotate);

    return 1;
}

int PowerManager::getCurrentMapName(UserInfo userInfo, string &mapNameReturn)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    robotManager->robotsMap.value(robotId)->threadMotionEngine->
            mcControllerInterpreter->getCurrentMapName(mapNameReturn);

    return 1;
}

int PowerManager::vehicleJog(UserInfo userInfo, int robotIdIn, double xMove, double yMove, double rotate)
{

    if(false==robotManager->robotsMap.contains(robotIdIn))
    {
        return -1;
    }
    watchDog->startDog();
    robotManager->robotsMap.value(robotIdIn)->threadMotionEngine->
            mcControllerInterpreter->vehicleJog(xMove,yMove,rotate);

    return 1;
}

int PowerManager::jogStop(UserInfo userInfo)
{
    if(0)
    {
            qDebug()<<"PowerManager::jogStop";
    }

    watchDog->resetDog();
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    robotManager->robotsMap.value(robotId)->threadMotionEngine->
            mcControllerInterpreter->vehicleJogStop();

    return 1;
}


int PowerManager::setMapSolver(UserInfo userInfo, E_MAP_SOLVER solverIn, int laserCount, int &returnFlag)
{
    qDebug()<<"PowerManager::setMapSolver begin";
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
        {
                rob->threadMotionEngine->mcControllerInterpreter->setMapSolver(solverIn,laserCount, returnFlag);
        }

    }
    return 0;//必须有，代表通信成功
}

int PowerManager::createMapStart(UserInfo userInfo, int &returnFlag)
{
    qDebug()<<"PowerManager::createMapStart begin";
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
        {
                rob->threadMotionEngine->mcControllerInterpreter->createMapStart(returnFlag);
        }

    }
    return 0;//必须有，代表通信成功
}

int PowerManager::createMapEnd(UserInfo userInfo, string mapName, int &returnFlag)
{
    qDebug()<<"PowerManager::createMapEnd begin";
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
        {
                rob->threadMotionEngine->mcControllerInterpreter->createMapEnd(mapName, returnFlag);
        }

    }
    return 0;//必须有，代表通信成功
}

int PowerManager::loadMap(UserInfo userInfo, string mapName, int &returnFlag)
{
    qDebug()<<"PowerManager::loadMap begin";
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter)
                && NULL!=fleetService )
        {

                fleetService->loadMap(mapName);
                rob->threadMotionEngine->mcControllerInterpreter->loadMap(mapName, returnFlag);
        }

    }
    return 0;//必须有，代表通信成功
}

int PowerManager::deleteMap(UserInfo userInfo, string mapName, int &returnFlag)
{
    if(disOPeratorPermission(userInfo))
    {
         globalManager->removeMapFile(mapName,returnFlag);

    }
    else
    {

    }
    return 0;
}

int PowerManager::addVitrualBlock(UserInfo userInfo, string configFilePath, int &returnFlag)
{
    qDebug()<<"PowerManager::addVitrualBlock begin";
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
        {
                rob->threadMotionEngine->mcControllerInterpreter->addVitrualBlock(configFilePath, returnFlag);
        }

    }
    return 0;//必须有，代表通信成功
}

int PowerManager::deleteVitrualBlock(UserInfo userInfo, int &returnFlag)
{
    qDebug()<<"PowerManager::deleteVitrualBlock begin";
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
        {
                rob->threadMotionEngine->mcControllerInterpreter->deleteVitrualBlock(returnFlag);
        }

    }
    return 0;//必须有，代表通信成功
}



int PowerManager::addForbidenZone(UserInfo userInfo, double x_start, double y_start, double x_end, double y_end, int &returnFlag)
{
    qDebug()<<"PowerManager::addForbidenZone begin";
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
        {
                rob->threadMotionEngine->mcControllerInterpreter->addForbidenZone(x_start,y_start,x_end,y_end, returnFlag);
        }

    }
    return 0;//必须有，代表通信成功
}

int PowerManager::setOdomSolver(UserInfo userInfo, E_ODOM_SOLVER solverIn, int &returnFlag)
{
    qDebug()<<"PowerManager::setOdomSolver begin";
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
        {
                rob->threadMotionEngine->mcControllerInterpreter->setOdomSolver(solverIn, returnFlag);
        }

    }
     return 0;//必须有，代表通信成功
    
}

int PowerManager::setLocationSolver(UserInfo userInfo, E_LOCATION_SOLVER solverIn,
                                    int &returnFlag)
{
    qDebug()<<"PowerManager::setLocationSolver begin";
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
        {
                rob->threadMotionEngine->mcControllerInterpreter->setLocationSolver(solverIn, returnFlag);
        }

    }
    return 0;//必须有，代表通信成功
}

int PowerManager::getVehiclePosition(UserInfo userInfo, VehiclePosition &positionReturn)
{
//    qDebug()<<"PowerManager::getVehiclePosition begin";
//    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
//    if( rob  )
//    {
//        if((NULL!=rob->threadMotionEngine)
//                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
//        {
//                rob->threadMotionEngine->mcControllerInterpreter->getVehiclePosition(positionReturn);
//        }

//    }
    PositionInfo_hmi tmp_position;
    getVehiclePosition_specified(userInfo,1,tmp_position);
    positionReturn=tmp_position.position;
    return 0;//必须有，代表通信成功
}

int PowerManager::getVehiclePosition_specified(UserInfo userInfo, int typeIn, PositionInfo_hmi &positionReturn)
{
    //    qDebug()<<"PowerManager::getVehiclePosition_specified begin";
        RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
        if( rob  )
        {
            if((NULL!=rob->threadMotionEngine)
                    && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
            {
                    PositionInfo tmpPosition;
                    rob->threadMotionEngine->mcControllerInterpreter->getVehiclePosition_specified(tmpPosition,(E_VEHICLE_POSITION_TYPE)typeIn);
                    positionReturn.position=tmpPosition.position;
                    positionReturn.isUpdateSucess=tmpPosition.isUpdateSucess;
                    positionReturn.maxMatchError=tmpPosition.maxMatchError;
                    positionReturn.matchScore=tmpPosition.matchScore;
            }

        }
        return 0;//必须有，代表通信成功
}

int PowerManager::setVehiclePosition(UserInfo userInfo, VehiclePosition positionIn, int &returnFlag)
{
    qDebug()<<"PowerManager::setVehiclePosition begin";
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
        {
                rob->threadMotionEngine->mcControllerInterpreter->setVehiclePosition(positionIn,1, returnFlag);
        }

    }
     return 0;//必须有，代表通信成功

}

int PowerManager::initialVehiclePosition_byProgramPoint(UserInfo userInfo,  int pointIndex, int &returnFlag)
{


    qDebug()<<"PowerManager::initialVehiclePosition_byProgramPoint begin";
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
        {
            QString tmpProgramFile;
            rob->getProgramSetRunFile(tmpProgramFile);
            DPoint pointOut;
            if(1!=rob->programEngine->getDpoint( tmpProgramFile.toStdString(),pointIndex, pointOut))
            {
                addMsg( ENUM_MSG_ERROR,  "PowerManager", "PowerManager",  6027,  1,pointIndex);
                return -1;
            }
            VehiclePosition positionIn;
            positionIn.x=pointOut.posX/1000.0;
            positionIn.y=pointOut.posY/1000.0;
            positionIn.rotate=M_PI*pointOut.posR/180.0;
            rob->threadMotionEngine->mcControllerInterpreter->setVehiclePosition(positionIn,D_SET_ODOMETER_COVE_RATIO, returnFlag);
            return 1;
        }

    }
     return 0;//必须有，代表通信成功
}

int PowerManager::setReplanCoutLimitWhenFailure(UserInfo userInfo, int countLimit, int &returnFlag)
{
    qDebug()<<"PowerManager::setReplanCoutLimitWhenFailure begin";
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
        {
                rob->threadMotionEngine->mcControllerInterpreter->setReplanCoutLimitWhenFailure(countLimit, returnFlag);
        }

    }
    return 0;//必须有，代表通信成功
}

int PowerManager::setTrajectoryGlobalPlanSolver(UserInfo userInfo, E_TRAJECTORY_GLOBAL_SOLVER solverIn, int &returnFlag)
{
    qDebug()<<"PowerManager::setTrajectoryGlobalPlanSolver begin";
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
        {
                rob->threadMotionEngine->mcControllerInterpreter->setTrajectoryGlobalPlanSolver(solverIn, returnFlag);
        }

    }
    return 0;//必须有，代表通信成功
}

int PowerManager::setTrajectoryLocalPlanSolver(UserInfo userInfo, E_TRAJECTORY_LOCAL_SOLVER solverIn, int &returnFlag)
{
    qDebug()<<"PowerManager::setTrajectoryLocalPlanSolver begin";
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
        {
                rob->threadMotionEngine->mcControllerInterpreter->setTrajectoryLocalPlanSolver(solverIn, returnFlag);
        }

    }
    return 0;//必须有，代表通信成功
}

int PowerManager::moveToPosition(UserInfo userInfo, VehiclePosition positionIn, double velocity, int &returnFlag)
{
    qDebug()<<"PowerManager::moveToPosition begin";
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
        {
                rob->threadMotionEngine->mcControllerInterpreter->moveToPosition(positionIn,velocity, returnFlag);
        }

    }
    return 0;//必须有，代表通信成功
}

int PowerManager::moveFollowPath(UserInfo userInfo, std::vector<VehiclePosition> pathIn, double velocity, int &returnFlag)
{
    qDebug()<<"PowerManager::moveFollowPath begin";
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
        {
                rob->threadMotionEngine->mcControllerInterpreter->moveFollowPath(pathIn,velocity, returnFlag);
        }

    }
    return 0;//必须有，代表通信成功
}

int PowerManager::changeVelocity(UserInfo userInfo, double velocity, int &returnFlag)
{
    qDebug()<<"PowerManager::changeVelocity begin";
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
        {
                rob->threadMotionEngine->mcControllerInterpreter->changeVelocity(velocity, returnFlag);
        }

    }
    return 0;//必须有，代表通信成功
}

int PowerManager::getMovingStatus(UserInfo userInfo, E_GOAL_STATUS &status)
{
    qDebug()<<"PowerManager::getMovingStatus begin";
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
        {
                rob->threadMotionEngine->mcControllerInterpreter->getMovingStatus(status);
        }

    }
    return 0;//必须有，代表通信成功
}

int PowerManager::getRemainningTime(UserInfo userInfo, double &timeOut)
{
    qDebug()<<"PowerManager::getRemainningTime begin";
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
        {
                rob->threadMotionEngine->mcControllerInterpreter->getRemainningTime(timeOut);
        }

    }
    return 0;//必须有，代表通信成功
}

int PowerManager::getRemainningDistance(UserInfo userInfo, double &distanceOut)
{
    qDebug()<<"PowerManager::getRemainningDistance begin";
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
        {
                rob->threadMotionEngine->mcControllerInterpreter->getRemainningDistance(distanceOut);
        }

    }
    return 0;//必须有，代表通信成功
}

int PowerManager::ceaseMotion(UserInfo userInfo, int &returnFlag)
{
    qDebug()<<"PowerManager::ceaseMotion begin";
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
        {
                rob->threadMotionEngine->mcControllerInterpreter->ceaseMotion( returnFlag);
        }

    }
    return 0;//必须有，代表通信成功
}

int PowerManager::startMotion(UserInfo userInfo, int &returnFlag)
{
    qDebug()<<"PowerManager::startMotion begin";
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
        {
                rob->threadMotionEngine->mcControllerInterpreter->startMotion(returnFlag);
        }

    }
    return 0;//必须有，代表通信成功
}

int PowerManager::cancelMotion(UserInfo userInfo, int &returnFlag)
{
    qDebug()<<"PowerManager::cancelMotion begin";
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
        {
                rob->threadMotionEngine->mcControllerInterpreter->cancelMotion(returnFlag);
        }

    }
    return 0;//必须有，代表通信成功
    
}

int PowerManager::setPositionArrivedAccuracy(UserInfo userInfo, double accuracyIn, int &returnFlag)
{
    qDebug()<<"PowerManager::setPositionArrivedAccuracy begin";
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
        {
                rob->threadMotionEngine->mcControllerInterpreter->setPositionArrivedAccuracy(accuracyIn, returnFlag);
        }

    }
    return 0;//必须有，代表通信成功
}

int PowerManager::setLocalPlanRange(UserInfo userInfo, double rangeIn, int &returnFlag)
{
    qDebug()<<"PowerManager::setLocalPlanRange begin";
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
        {
                rob->threadMotionEngine->mcControllerInterpreter->setLocalPlanRange(rangeIn,returnFlag);
        }

    }
    return 0;//必须有，代表通信成功
}

int PowerManager::setVehicleBorderOffset(UserInfo userInfo, double front_offsetIn,
                                         double back_offsetIn, double left_offsetIn, double right_offsetIn)
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    robotManager->robotsMap.value(1)->threadMotionEngine->
            mcControllerInterpreter->setVehicleBorderOffset(front_offsetIn,back_offsetIn,left_offsetIn,right_offsetIn);

    return 1;
}

int PowerManager::setVehicleBorderOffset(UserInfo userInfo, std::vector<double> point_x, std::vector<double> point_y, int &returnFlag)
{
    qDebug()<<"PowerManager::setVehicleBorderOffset begin";
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
        {
                rob->threadMotionEngine->mcControllerInterpreter->setVehicleBorderOffset(point_x,point_y,returnFlag);
        }

    }
    return 0;//必须有，代表通信成功
}

int PowerManager::setGlobalBarrierOffset(UserInfo userInfo, double offsetIn, int &returnFlag)
{
    qDebug()<<"PowerManager::setGlobalBarrierOffset begin";
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
        {
                rob->threadMotionEngine->mcControllerInterpreter->setGlobalBarrierOffset(offsetIn, returnFlag);
        }

    }
    return 0;//必须有，代表通信成功
}
int PowerManager::setLocalBarrierOffset(UserInfo userInfo, double offsetIn, int &returnFlag)
{
    qDebug()<<"PowerManager::setLocalBarrierOffset begin";
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
        {
                rob->threadMotionEngine->mcControllerInterpreter->setLocalBarrierOffset(offsetIn, returnFlag);
        }

    }
    return 0;//必须有，代表通信成功
}

int PowerManager::resetRosAll(UserInfo userInfo, int &returnFlag)
{
    qDebug()<<"PowerManager::resetRosAll begin";
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
        {
                rob->threadMotionEngine->mcControllerInterpreter->resetRosAll(returnFlag);
        }

    }
    return 0;//必须有，代表通信成功
}

int PowerManager::getRosPackageStatus(UserInfo userInfo,E_ROS_PACKAGE package, E_ROS_PACKAGE_STATUS &status)
{
    qDebug()<<"PowerManager::getRosPackageStatus begin";
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
        {
                rob->threadMotionEngine->mcControllerInterpreter->getRosPackageStatus(package,status);
        }

    }
    return 0;//必须有，代表通信成功
}

int PowerManager::startImuCalibrate(UserInfo userInfo, int &returnFlag)
{
    qDebug()<<"PowerManager::startImuCalibrate begin";
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
        {
                rob->threadMotionEngine->mcControllerInterpreter->startImuCalibrate(returnFlag);
        }

    }

    return 0;//必须有，代表通信成功
}

int PowerManager::stopImuCalibrate(UserInfo userInfo, int &returnFlag)
{
    qDebug()<<"PowerManager::stopImuCalibrate begin";
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( rob  )
    {
        if((NULL!=rob->threadMotionEngine)
                && (NULL!=rob->threadMotionEngine->mcControllerInterpreter))
        {
                rob->threadMotionEngine->mcControllerInterpreter->stopImuCalibrate(returnFlag);
        }

    }

    return 0;//必须有，代表通信成功
}

int PowerManager::motorBatteryCheck()
{
    RobotInfo* robInfo;
    foreach ( robInfo, robotManager->robotsInfoMap )
    {
        if( robInfo )
        {
            bool tmpResult=robotManager->robotsMap.value(robInfo->robotId)->threadMotionEngine
                    ->mcControllerInterpreter->isAbsoulteMotorBatteryOk();
            if(false==tmpResult)
            {
                qDebug()<<"error----------------------------------------------------------"
                       <<"PowerManager::motorBatteryCheck(),false;robInfo->robotId="
                       <<robInfo->robotId;
                addMsg( ENUM_MSG_ERROR,  "PowerManager", "PowerManager",  6021,  robInfo->robotId);
            }
        }
    }

    return 1;
}

void PowerManager::Init()
{
    // m_pMd5Instance = MD5Check::getInstance();
     messageLog =   MessageLog::getInstance();
     robotManager = new RobotManager();
     globalManager = new GlobalManager(-1,robotManager);
     ctlRobotiq = new CommRobotiq();
     QString tmpPathName = D_TCRCONTROLLER_DATA_PATH;
     tmpPathName = tmpPathName+USER_INFO;

     QString licensePathName= D_TCRCONTROLLER_DATA_PATH;
     licensePathName = licensePathName+LICENSE_FILE_MAIN;

     authority=new AuthorityAllowance(tmpPathName,licensePathName);
     watchDog=new SafeWatchDog(1500,300,this,0);



   //  qDebug() << "====PowerManager==11111==="<<robotManager->robotsMap.keys();
     QList <int> robotIdVec = robotManager->robotsMap.keys();
    // qDebug() << "===robotIdVec==="<<robotIdVec.size();
     for(int i = 0; i < robotIdVec.size();i++)
     {
         robotServoFlagVec.insert(robotIdVec[i],false);
     }
    // qDebug() << "====PowerManager==22222===";



     addMsg( ENUM_MSG_REMIND,  "PowerManager", "PowerManager",  1001,  -1);

     checkRegisterStatus();

    safetyFunction= new SafetyFunction();

}

void PowerManager::watchDogFailedProcessFunction()
{
    qDebug()<<"watchDogFailedProcessFunction run";
    addMsg( ENUM_MSG_WARNING,  "PowerManager", "PowerManager",  6019,  -1);

    watchDog->resetDog();
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return ;
    }
    robotManager->robotsMap.value(robotId)->threadMotionEngine->
            mcControllerInterpreter->vehicleJogStop();
    robotManager->robotsMap.value(robotId)->resetProgram();
    watchDog->resetDog();

}

int PowerManager::startSafetyCheck()
{
    //初始化安全模块
    return safetyFunction->startSafetyCheck();

}

ProgramEngine *PowerManager::getProgramEngine(int robotIdIn)
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return NULL;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return NULL;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return NULL;
    }
    return rob->programEngine;
}

McControllerInterpreter *  PowerManager::isMotionServerInitialOk(int robotIdIn)
{
    if(false==robotManager->robotsMap.contains(robotIdIn))
    {
        return NULL;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return NULL;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return NULL;
    }
    return rob->threadMotionEngine->mcControllerInterpreter;
}

//int PowerManager::setFleetService(FleetService *fleetServiceIn)
//{
//    fleetService=fleetServiceIn;
//    return 1;
//}

int PowerManager::setAgvTargetAllowOffset(float allowLineOffsetIn, float allowAngleOffsetIn)
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    return robotManager->robotsMap.value(1)->threadMotionEngine->
            mcControllerInterpreter->setAgvTargetAllowOffset(allowLineOffsetIn,allowAngleOffsetIn);

    return 1;
}

int PowerManager::setAgvPathFollowStrategy(E_PATH_CONTROL_STRATEGY stragetyIn)
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    return robotManager->robotsMap.value(1)->threadMotionEngine->
            mcControllerInterpreter->setAgvPathFollowStrategy(stragetyIn);

    return 1;
}

int PowerManager::setMotionServerModel(MC_MOTION_MODEL modelIn)
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    return robotManager->robotsMap.value(1)->threadMotionEngine->
            mcControllerInterpreter->setMotionServerModel(modelIn);

    return 1;
}

int PowerManager::setOdomSolver(E_ODOM_SOLVER solverIn, int &returnFlag)
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    return robotManager->robotsMap.value(1)->threadMotionEngine->
            mcControllerInterpreter->setOdomSolver(solverIn,returnFlag);

    return 1;
}

int PowerManager::changeToPositionType(E_VEHICLE_POSITION_TYPE typeIn)
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    return robotManager->robotsMap.value(1)->threadMotionEngine->
            mcControllerInterpreter->changeToPositionType(typeIn);

    return 1;
}

int PowerManager::setCheckVehiclePosition(E_VEHICLE_POSITION_TYPE typeIn, bool isCheck)
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    return robotManager->robotsMap.value(1)->threadMotionEngine->
            mcControllerInterpreter->setCheckVehiclePosition(typeIn,isCheck);

    return 1;
}

int PowerManager::setVehicleAcceleration(double accelerationIn)
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    return robotManager->robotsMap.value(1)->threadMotionEngine->
            mcControllerInterpreter->setVehicleAcceleration(accelerationIn);

    return 1;
}

int PowerManager::setVehicleAcceleration_rotate(double accelerationIn)
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    return robotManager->robotsMap.value(1)->threadMotionEngine->
            mcControllerInterpreter->setVehicleAcceleration_rotate(accelerationIn);

    return 1;
}

int PowerManager::setVirtualLineEnableKpChange(bool isEnable)
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    return robotManager->robotsMap.value(1)->threadMotionEngine->
            mcControllerInterpreter->setVirtualLineEnableKpChange(isEnable);

    return 1;
}

int PowerManager::setLaserIntensityFilterByType_visionMatch(int typeIn)
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    return robotManager->robotsMap.value(1)->threadMotionEngine->
            mcControllerInterpreter->setLaserIntensityFilterByType_visionMatch(typeIn);

    return 1;
}

int PowerManager::setCurrentVMarkType(int currentVmarkTypeIn)
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    return robotManager->robotsMap.value(1)->threadMotionEngine->
            mcControllerInterpreter->setCurrentVMarkType(currentVmarkTypeIn);

    return 1;
}

int PowerManager::isVirtualLineTrajectoryEmpty()
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    return robotManager->robotsMap.value(1)->threadMotionEngine->
            mcControllerInterpreter->isVirtualLineTrajectoryEmpty();

    return 1;
}

int PowerManager::addVirtualLineTrajectoryCommand(QVector<NavParameter> commandVectorIn)
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    return robotManager->robotsMap.value(1)->threadMotionEngine->
            mcControllerInterpreter->addVirtualLineTrajectoryCommand(commandVectorIn);

    return 1;
}

int PowerManager::motion_allCease()
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    return robotManager->robotsMap.value(1)->threadMotionEngine->
            mcControllerInterpreter->allCease();

    return 1;
}

int PowerManager::motion_allStop()
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    return robotManager->robotsMap.value(1)->threadMotionEngine->
            mcControllerInterpreter->allStop();

    return 1;
}

int PowerManager::motion_allStartRun_fleet()
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    return robotManager->robotsMap.value(1)->threadMotionEngine->
            mcControllerInterpreter->allStartRun_fleet();

    return 1;
}

int PowerManager::motion_allStartRun()
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    return robotManager->robotsMap.value(1)->threadMotionEngine->
            mcControllerInterpreter->allStartRun();

    return 1;
}

float PowerManager::getRunningNumber_virtualLineControl()
{
    if(false==robotManager->robotsMap.contains(1))
    {
        return -1;
    }
    return robotManager->robotsMap.value(1)->threadMotionEngine->
            mcControllerInterpreter->getRunningNumber_virtualLineControl();

    return 1;
}

int PowerManager::checkRegisterStatus()
{

    int returnKey=authority->refreshAuthorityStatus();

    switch(returnKey)
    {
        case ENUM_TIME_GOING_PASSED:
        {
            addMsg( ENUM_MSG_REMIND,  "PowerManager", "PowerManager",  6012,  -1);
            break;
        }
        case ENUM_TIME_PASSED:
        {
            addMsg( ENUM_MSG_REMIND,  "PowerManager", "PowerManager",  6013,  -1);
            break;
        }
        case ENUM_SERIAL_UNEQUAL:
        {
            addMsg( ENUM_MSG_REMIND,  "PowerManager", "PowerManager",  6014,  -1);
            break;
        }
        case ENUM_REGISTER_FILE_NO_EXIST:
        {
            addMsg( ENUM_MSG_REMIND,  "PowerManager", "PowerManager",  6015,  -1);
            break;
        }
        case ENUM_REGISTER_FILE_NODE_ERROR:
        {
            addMsg( ENUM_MSG_REMIND,  "PowerManager", "PowerManager",  6016,  -1);
            break;
        }

        case ENUM_REGISTER_FILE_CHECK_CODE_ERROR:
        {
            addMsg( ENUM_MSG_REMIND,  "PowerManager", "PowerManager",  6017,  -1);
            break;
        }
        case ENUM_BOOT_COUNT_EXCEED:
        {
            addMsg( ENUM_MSG_REMIND,  "PowerManager", "PowerManager",  6018,  -1);
            break;
        }
    }

    return returnKey;
}

int PowerManager::registerComponentVersion(ComponentVersion componentVersionInfo)
{
    pthread_mutex_lock(&versionMutex);
    myComponentVersionList.push_back(componentVersionInfo);
    pthread_mutex_unlock(&versionMutex);
    return 1;
}

int PowerManager::readVersion(std::vector <ComponentVersion> &componentVersionList)
{

    componentVersionList.push_back(versionInfo);
    return 1;
}

std::vector<ComponentVersion> PowerManager::refreshVersionList()
{
    pthread_mutex_lock(&versionMutex);
    robotManager->readVersion(myComponentVersionList);
    robCtl->readVersion(myComponentVersionList);
    std::vector<ComponentVersion> versionListReturn=myComponentVersionList;
    pthread_mutex_unlock(&versionMutex);

    return versionListReturn;

}

void PowerManager::getSoftLimit(std::vector<std::vector<float> > &axisLimit, std::vector<int> &axisUnit)
{
    robotManager->robotsMap.value(robotId)->threadMotionEngine->mcControllerInterpreter->getSoftLimit(axisLimit,axisUnit);
}

int PowerManager::checkPcHmiVersion(string hmiVerInfo)
{
    QString tmpVersion=QString::fromStdString(hmiVerInfo);
    int mainVersion,subVersion;
    QString pattern = "V(\\d+).(\\d+)\\s*(.*)";
    QRegExp rx(pattern);
    bool isMatch=rx.exactMatch(tmpVersion);

    mainVersion=rx.cap(1).toInt();
    subVersion=rx.cap(2).toInt();

    qDebug()<<"111111 hmiVerInfo"<<tmpVersion<<"mainVersion"<<mainVersion<<"subVersion"<<subVersion;
    if(mainVersion<2 )
    {
        return -1;//不允许登录
    }
    else
    {
        if(subVersion<1 )
        {
            return 0;//允许登录，提示升级版本
        }
    }

    return 1;
}

int PowerManager::checkWebHmiVersion(string hmiVerInfo)
{
    return 1;
}

bool PowerManager::disOPeratorPermission(UserInfo userInfo)
{
    bool flag = false;


    if(ENUM_POWER_ADMIN == userInfo.account)
    {
        flag = true;
    }
    else if(ENUM_POWER_COMMON_CONSUMER == userInfo.account)
    {
        flag = false;
        //消息预留
        //当前用户没有权限进行此操作
        addMsg( ENUM_MSG_REMIND,  "PowerManager", "PowerManager",  6001,  robotId);
        qDebug()<<"没有权限! ";
    }
  //  qDebug() << "++++disOPeratorPermission+++++"<<userInfo.account<<"===flag==="<<flag<<"\n\n\n\n\n";
    return flag;
}

int PowerManager::setIpAddress(UserInfo userInfo, ControllerIpGroupInfo controllerIpGroupInfo, int &returnFlag)
{
    if(disOPeratorPermission(userInfo))
    {
        setIpAddress(controllerIpGroupInfo);
        //预留接口通过ｒｏｂｏｔＭａｎａｇｅｒ调用当前的机器人指针，globalManager修改ＩＰ
        returnFlag = 0;
    }
    else
    {
         returnFlag = 1; //没有权限
    }

    return returnFlag;
}

int PowerManager::setMacAddress(UserInfo userInfo, string macAddress, int &returnFlag)
{
    if(disOPeratorPermission(userInfo))
    {
        setMacAddress(QString::fromStdString(macAddress));
        //预留接口通过ｒｏｂｏｔＭａｎａｇｅｒ调用当前的机器人指针，调用ｇｌｏｂａｌＭａｎａｇｅｒ修改ｍａｃ
        returnFlag = 0;
    }
    else
    {
         returnFlag = 1; //没有权限
    }

    return returnFlag;
}

int PowerManager::readDefaultFileName(struct UserInfo userInfo, std::string  &returnFlag)
{
    //判断缺省文件是否存在，若存在则打开文件
    qDebug() << "====default==File===="<<robotId;
    if(NULL == robotManager->robotsMap.value(robotId))
    {
        qDebug() << "====default==File===empty******=\n";
    }
    else
    {
        bool defaultFlag = robotManager->robotsMap.value(robotId)->readDefaultFileSetting();
        if(defaultFlag)
        {
            qDebug() << "====default==File===="<<robotManager->robotsMap.value(robotId)->defaultFile<<endl;
            robotManager->robotsMap.value(robotId)->openFile( QString::fromStdString(robotManager->robotsMap.value(robotId)->defaultFileName) );
            returnFlag = robotManager->robotsMap.value(robotId)->defaultFileName;
        }
        else
        {
             returnFlag = "";
        }


    }

    return 0;
}

int PowerManager::setLanguage(UserInfo userInfo, int languageID, int &returnFlag)
{
//    if(disOPeratorPermission(userInfo))
//    {
    qDebug()<<"no function, need to do , PowerManager::setLanguage(UserInfo userInfo, int languageID, int &returnFlag)";
        //MessageLog::getInstance()->changeMessageLanguage(languageID);
        returnFlag = 0;
//    }
//    else
//    {
//        returnFlag = 1;
//    }
    return returnFlag;
}

int PowerManager::setStartType(UserInfo userInfo, int type, string &returnFlag)
{
    if(disOPeratorPermission(userInfo))
    {
         globalManager->setStartType(type);

    }
    else
    {

    }
    return 0;
}

int PowerManager::changePasswd(UserInfo userInfo, int changeAccount,string oldPasswd, string newPasswd, int &returnFlag)
{
    int returnKey=authority->changePasswd(userInfo,changeAccount,oldPasswd,newPasswd,returnFlag);
    if(-1==returnKey)
    {
             addMsg( ENUM_MSG_REMIND,  "PowerManager", "PowerManager",  6003,  robotId);
    }
    else if(-2==returnKey)
    {
            addMsg( ENUM_MSG_REMIND,  "PowerManager", "PowerManager",  6001,  robotId);
    }
    else if(0==returnKey)
    {
            addMsg( ENUM_MSG_REMIND,  "PowerManager", "PowerManager",  6030,  robotId);
    }


    return returnFlag;
}

int PowerManager::setTimerReg(UserInfo userInfo, int timerNumber, int changeStatus, int &returnFlag)
{
    //如果普通用户可以进行该项操作的话，则不需要进行词句的判断，且returnFlag为０
    if(disOPeratorPermission(userInfo))
    {
        robotManager->robotsMap.value(robotId)->programEngine->regData->setRegTimer(timerNumber,changeStatus,0);
        returnFlag = 0;
    }
    else
    {
        qDebug()<<"设置工具坐标系失败: 没有权限";
         returnFlag = 1; //没有权限
    }
    return returnFlag;
}



int PowerManager::getHardDiskInfo(UserInfo userInfo, double & totalVolume, double & freeVolume)
{
    globalManager->getHardDiskInfo(totalVolume,freeVolume);
    return 1;
}

int PowerManager::getRamInfo(UserInfo userInfo,double & totalVolume, double & freeVolume)
{
    globalManager->getRamInfo(totalVolume,freeVolume);
    return 1;
}

int PowerManager::getCpuInfo(UserInfo userInfo,double & usedRatio)
{
   globalManager->getCpuInfo(usedRatio);
   return 1;
}

int PowerManager::setUToolActive(UserInfo userInfo, int number, int &returnFlag)
{
    //如果普通用户可以进行该项操作的话，则不需要进行词句的判断，且returnFlag为０
    if(disOPeratorPermission(userInfo))
    {
        int ret=robotManager->robotsMap.value(robotId)->threadMotionEngine->mcControllerInterpreter->activateToolCoordinate(number);
        if(ret!=0){
            //消息预留
            qDebug()<<"设置工具坐标系:"<<number;
             returnFlag = 0;
        }else{
            //消息预留
            qDebug()<<"设置工具坐标系失败:编号无效";
            returnFlag =1;
        }
    }
    else
    {
        qDebug()<<"设置工具坐标系失败: 没有权限";
         returnFlag = 1; //没有权限
    }
}

int PowerManager::setUFrameActive(UserInfo userInfo, int number, int &returnFlag)
{
    //如果普通用户可以进行该项操作的话，则不需要进行词句的判断，且returnFlag为０
    if(disOPeratorPermission(userInfo))
    {
       int ret = robotManager->robotsMap.value(robotId)->threadMotionEngine->mcControllerInterpreter->activateUserCoordinate(number);
       if(ret!=0){
           //消息预留
           qDebug()<<"设置用户坐标系:"<<number;
            returnFlag = 0;
       }else{
           //消息预留
           qDebug()<<"设置用户坐标系失败: 编号无效";
           returnFlag = 1;
       }
    }
    else
    {
        qDebug()<<"设置用户坐标系失败: 没有权限";
         returnFlag = 1; //没有权限
    }
}

int PowerManager::getUToolActive(UserInfo userInfo, int &returnUToolNum)
{
    returnUToolNum = robotManager->robotsMap.value(robotId)->threadMotionEngine->mcControllerInterpreter->getToolIndex();
}

int PowerManager::getUFrameActive(UserInfo userInfo, int &returnUFrameNum)
{
    returnUFrameNum = robotManager->robotsMap.value(robotId)->threadMotionEngine->mcControllerInterpreter->getUserIndex();
}

int PowerManager::getProgramSetRunFile(QString &fileName)
{
    qDebug()<<"PowerManager::initialVehiclePosition_byProgramPoint begin";
    RobotEngine* rob = robotManager->robotsMap.value( 1, NULL );
    if( rob  )
    {

            rob->getProgramSetRunFile(fileName);
            return 1;
    }
    return 0;//必须有，代表通信成功
}

int PowerManager::getControllerAllInformation(UserInfo userInfo, bool isContainIoData, bool isContainAgvData,
                                              bool isContainPointCloud, ControllerInformationAll &infoOut)
{
    updateControllerInfoLevel1(userInfo,robotId,infoOut.dataLv1);
    updateControllerInfoLevel2(userInfo,infoOut.dataLv2);
    if(isContainIoData)
    {
        updateControllerInfoLevel3(userInfo,infoOut.dataLv3);
    }
    //message
    updateControllerMessage(userInfo,infoOut.messageVector);

    if(isContainAgvData)
    {
        updateControllerInfoLevel2_agv(userInfo,infoOut.dataLv2_agv);
    }
    if(isContainPointCloud)
    {
        getAllPointCloud_translated(userInfo,infoOut.pointCloud);
    }
    infoOut.isReturnSucess=true;
    return 1;


}

int PowerManager::updateControllerInfoLevel1(UserInfo userInfo,int robotIdIn,
                                             UpdateDataLv1 &updateDataLv1)
{
   // timeTest_1 ->recordInTime();
//    qDebug() << "PowerManager::updateControllerInfoLevel1 begin,,,,";
    initControllerStatus(userInfo,updateDataLv1.controllerInitialStatus);
    QList<int> robotIdList= robotManager->robotsMap.keys();
    if(false==robotManager->robotsMap.contains(robotIdIn))
    {
        qDebug()<<"warn,,,,,,,,,PowerManager::updateControllerInfoLevel1,robotIdIn not exist"<<robotIdIn;
//        if( 0==robotIdIn )
//        {
//            robotId= robotIdList.at(0);
//        }
    }
    else
    {
//        robotId=robotIdIn;
//        qDebug()<<"~~~~~~~~~切换机器人id"<<robotId<<"成功!!!";
    }


    pthread_mutex_lock(&versionMutex);
    updateDataLv1.componentVersionList=myComponentVersionList;
    pthread_mutex_unlock(&versionMutex);
    updateDataLv1.globalRegStatus = authority->getAuthorityStatus();
    updateDataLv1.globalLockMachTime = authority->getLockTime().toStdString();
    updateDataLv1.registerNumber = authority->getRegisterNumber().toStdString();

    updateDataLv1.serialNumber = authority->getHardDiskSerialNumber().toStdString();

    //获取基本的配置信息　从文件中读取网卡名
    readBaseData();

    //通过网卡名获取控制器的ｉｐ地址
    controllerIp = ipAddress(networkName);
    //通过ｍａｃ地址获取控制器的ｍａｃ地址
    controllerMac = macAddress(networkName);

    updateDataLv1.controllerIp = controllerIp.toStdString();
    updateDataLv1.controllerMac = controllerMac.toStdString();

    int robotcount=robotManager->robotsMap.size();

    //添加所有机器人信息
    if(robotcount>=0)
    {
        updateDataLv1.robotInfoList.resize( robotcount );
    }

    for(int i=0;i<robotIdList.size(); i++ )
    {
        int robId = robotIdList.at(i);
        CommRobotInfo tmpCommRobotInfo;
        tmpCommRobotInfo.robotId = robotManager->robotsInfoMap.value( robId )->robotId;
        tmpCommRobotInfo.robotName = robotManager->robotsInfoMap.value( robId )->robotName.toStdString();
        tmpCommRobotInfo.robotSpecification = robotManager->robotsInfoMap.value( robId )->robotSpecification;
        tmpCommRobotInfo.robotType = robotManager->robotsInfoMap.value( robId )->robotType;
        tmpCommRobotInfo.robotFileAddress = robotManager->robotsInfoMap.value( robId )->robotFileAddress;
        tmpCommRobotInfo.robotPictureAddress = robotManager->robotsInfoMap.value( robId )->robotPictureAddress;

        tmpCommRobotInfo.robotStatus =   robotManager->robotsMap.value( robId )->threadMotionEngine->mcControllerInterpreter->getStatus();// 机器人运行状态
        // 2017-3-10  修改 将原来的autoRatio改成getAutoRatio()
        tmpCommRobotInfo.robotRunSpeed = robotManager->robotsMap.value( robId )->threadMotionEngine->mcControllerInterpreter->getAutoRatio();//自动速度倍率
        tmpCommRobotInfo.robotProgram = robotManager->robotsMap.value( robId )->defaultFile.toStdString() ;

        updateDataLv1.robotInfoList[i]=tmpCommRobotInfo;
    }

    if(false==robotManager->robotsMap.contains(robotIdIn))
    {
        return 1;
    }

    RobotEngine* rob = robotManager->robotsMap.value( robotIdIn, NULL );
    if( rob  )
    {
        if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData)
                )
        {
            qDebug() << "error,,,,***********this is empty!!!!!!!!!!!\n\n"
                     << rob->threadMotionEngine
                     << rob->threadMotionEngine->mcControllerInterpreter
                     << rob->programEngine
                     << rob->programEngine->regData
                     <<endl;
            return 0;
        }

        //轴数
        int axisNum = rob->robotInfo.robotMotorCount;
        updateDataLv1.robotAxisCount = axisNum;

        //外部轴数
        int extAxisNum = rob->robotInfo.extMotorCount;
        updateDataLv1.extAxisCount =  extAxisNum;

        //轴信息（外部轴的信息全部统一到所有轴vector里面）
        rob->threadMotionEngine->mcControllerInterpreter->getAxisInformation(updateDataLv1.axisLimit,
                                  updateDataLv1.extAxisLimit,updateDataLv1.axisUnit,updateDataLv1.extAxisUnit
                                  ,updateDataLv1.axisType,updateDataLv1.extAxisType);

    }
//    qDebug()<< "powerManager:: HMI login sucess================="
//            <<"innerAxis="<<   updateDataLv1.robotAxisCount
//           <<",externAxis="<<   updateDataLv1.extAxisCount
//              <<",robotId="<<robotId;

   // timeTest_1 ->recordOutTime();
    return 1;
}

int PowerManager::changeCurrentRobotId(UserInfo userInfo, int robotIdIn, int &returnFlag)
{
    if(false==robotManager->robotsMap.contains(robotIdIn))
    {
        qDebug()<<"failed,,,,,,,,,PowerManager::changeCurrentRobotId,robotIdIn not exist"<<robotIdIn;
        returnFlag=0;
    }
    else
    {
        robotId=robotIdIn;
        returnFlag=1;
        qDebug()<<"~~~~~~~~~切换机器人id"<<robotId<<"成功!!!";
    }
    return returnFlag;
}

#include <QTime>
//获取所有的更新数据
int PowerManager::updateControllerInfoLevel2(UserInfo userInfo, UpdateDataLv2 &updateDataLv2)
{
    //watchDog->feedDog();

   // timeTest_2 ->recordInTime();
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( rob  )
    {
        if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
        {
            qDebug() << "***updateControllerInfoLevel2*******point empty!!!!!!!!!!!\n\n"
                     << rob->threadMotionEngine
                     << rob->threadMotionEngine->mcControllerInterpreter
                     << rob->programEngine
                     << rob->programEngine->regData
                     <<endl;

            return 0;
        }
        ////============================

       // timeTest_6 ->recordInTime();
        rob->programEngine->updateControllerInfoLevel2( updateDataLv2 );//界面卡死与此行无关。
       // timeTest_6 ->recordOutTime();

        updateDataLv2.currentTime = QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss").toStdString();

        //  timeTest_4 ->recordInTime();
        ///算法　１）可能　pthread_mutex_lock(&getMutex);
        rob->threadMotionEngine->mcControllerInterpreter->updateControllerInfoLevel2( updateDataLv2 );

        //更新产量信息
         rob->programEngine->regData->getProduction(updateDataLv2.currentProductivity,
                                                    updateDataLv2.accumulateProductivity);
         rob->programEngine->regData->getWorkPieceRatio(updateDataLv2.workpieceRatio);


        //ecat　2) pthread_mutex_lock(&trajMutex);
        QVector<ServoState> motorDataInfo;
         if( eMasterOP==robCtl->getMasterState() )
        {

           // timeTest_5 ->recordInTime();
            motorDataInfo=  robCtl->getServoDataRobot( robotId );
           // timeTest_5 ->recordOutTime();

            updateDataLv2.globalSafePointFlag
                    = updateDataLv2.globalHandSwitch
                    = updateDataLv2.globalServoState
                    = rob->threadMotionEngine->mcControllerInterpreter->isServoOn();//coredump

            int robotAxisNumber = motorDataInfo.size();
            if(motorDataInfo.size()>0)
            {
                //预留接口暂时只提供绝对式的编码方式
                //updateDataLv2.globalZeroStatus
                updateDataLv2.globalZeroStatus = (int)motorDataInfo.at(0).isServoHomingOk;
                updateDataLv2.emergencyStatus = (int)motorDataInfo.at(0).isServoQuickStop;

                ///回零第二个标志位保留
                //            if( (int)stateData.at(0)->isServoHoming )
                //                updateDataLv2.globalZeroCtrlFlag = (int)stateData.at(0)->isServoHoming;

                updateDataLv2.axisPosition.resize(robotAxisNumber);
                updateDataLv2.axisSpeed.resize(robotAxisNumber);
                updateDataLv2.axisTorque.resize(robotAxisNumber);
                updateDataLv2.axisFollowOffset.resize(robotAxisNumber);

                for(int i = 0; i < robotAxisNumber;i++)
                {
                    updateDataLv2.axisPosition[i] = motorDataInfo[i].position;
                    updateDataLv2.axisSpeed[i] = motorDataInfo[i].speed;
                    updateDataLv2.axisTorque[i] = motorDataInfo[i].torque;
                    updateDataLv2.axisFollowOffset[i] = motorDataInfo[i].fllowingOffset;
                }
            }
        }
        else if( eMasterUnknown==robCtl->getMasterState() )
        {
            updateDataLv2.globalSafePointFlag
                    = updateDataLv2.globalHandSwitch
                    = updateDataLv2.globalServoState
                    = robotManager->robotsMap.value(robotId)->threadMotionEngine->mcControllerInterpreter->isServoOn();
        }


    }

    return 1;
    // timeTest_2 ->recordOutTime();
}


int PowerManager::updateControllerInfoLevel2_agv(UserInfo userInfo,
                                                 struct VehicleBasicInfo &vehicleInfo)
{

   // timeTest_2 ->recordInTime();
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( rob  )
    {
        if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData)
                ||(NULL==fleetService))
        {
            qDebug() << "***updateControllerInfoLevel2_agv*******point empty!!!!!!!!!!!\n\n"
                     << rob->threadMotionEngine
                     << rob->threadMotionEngine->mcControllerInterpreter
                     << rob->programEngine
                     << rob->programEngine->regData
                     <<endl;

            return 0;
        }


         //agv相关信息
         getVehicleSpeedFeedback(userInfo,vehicleInfo.vehicleVelocityFeedback);
         getOdometer_positionManage(userInfo,vehicleInfo.odometer_history,
                                    vehicleInfo.time_history,
                             vehicleInfo.odometer_user,
                                    vehicleInfo.time_user);
         BatteryInformation batteryInfoOut;
         getBatteryInfo(batteryInfoOut);
         vehicleInfo.batteryLightModeLeft=batteryInfoOut.batteryLeftLightmodRatio;
         getPointCloudSafeStatus(vehicleInfo.pointSensorName,vehicleInfo.pointSensorSafeRatio,
                                         vehicleInfo.pointSensorCheckEnable);
         getUltrasonicSensorSafeStatus(vehicleInfo.ultrasonicSafeStatus,
                                       vehicleInfo.ultrasonicCheckEnable);
         getUltrasonicDetectDistance(vehicleInfo.ultrasonicDistance);
         getUltrasonicSensorName(vehicleInfo.ultrasonicSensorName);

         VirtualLineDebugInfo virtualInfoOut;
         getVirtualLineControlDebugInfo(userInfo,virtualInfoOut);
         vehicleInfo.absoluteDistanceLeft=virtualInfoOut.absoluteDistance;
         vehicleInfo.absoluteAngleLeft=virtualInfoOut.absoluteAngle;

         getVMarkPositionInWorld(userInfo,vehicleInfo.vmarkInWorld);
         getVehiclePosition_specified(userInfo,6,vehicleInfo.vehicleInVmark);
         getVehiclePosition_specified(userInfo,1,vehicleInfo.vehicleInWorld);
         getVehiclePosition_specified(userInfo,9,vehicleInfo.vehicleInQrcode);
         getVehiclePosition_specified(userInfo,10,vehicleInfo.vehicleInCU1);
         //path info
         int tmpPointIndex;
         E_NAV_COMMAND tmpPathType;
         QVector<VehiclePosition> tmpTargetList;
         rob->threadMotionEngine->mcControllerInterpreter->getCurrentPathInformation(vehicleInfo.startPosition,
                                tmpTargetList,tmpPointIndex,tmpPathType,
                                 vehicleInfo.currentPathParameter1,vehicleInfo.currentPathParameter2);
         vehicleInfo.targetPosition=tmpTargetList.toStdVector();
         vehicleInfo.currentPathType=tmpPathType;

         vehicleInfo.barrierMethod=rob->threadMotionEngine->mcControllerInterpreter->getBarrierRunMode();
         vehicleInfo.currentBorderId=rob->threadMotionEngine->mcControllerInterpreter->getCurrentVehicleBorderId();
         E_VEHICLE_POSITION_TYPE positionTypeOut;
         rob->threadMotionEngine->mcControllerInterpreter->getVehiclePositionType(positionTypeOut);
         vehicleInfo.usingPositionType= positionTypeOut;

         E_LASER_FILTER_TYPE laserFiltertypeOut;
         rob->threadMotionEngine->mcControllerInterpreter->getCurrentOriginalLaserFilterType(laserFiltertypeOut);
         vehicleInfo.originalLaserFilterType=laserFiltertypeOut;

         std::string currentMapName;
         rob->threadMotionEngine->mcControllerInterpreter->getCurrentMapName(currentMapName);
         vehicleInfo.currentMapName=currentMapName;

         vehicleInfo.currentFloorId=fleetService->getCurrentFloorId();
         PathMovingInfo pathInfoOut;
         getPathMovingInfo_virtualLineControl(pathInfoOut);
         vehicleInfo.pathMoveingInfo=pathInfoOut;

         vehicleInfo.mapVersion=fleetService->getMapVersion();
         E_AGV_STATE agvStateOut;
         fleetService->getCurrentAgvState(userInfo,agvStateOut);
         vehicleInfo.fleetBasicStatus=agvStateOut;
         rob->threadMotionEngine->mcControllerInterpreter->getCarBorderOffset(vehicleInfo.validCarBorder);

         rob->threadMotionEngine->mcControllerInterpreter->getOdometer(vehicleInfo.encoderOdom.vel,vehicleInfo.encoderOdom.pos);


    }

    return 1;
    // timeTest_2 ->recordOutTime();
}

int PowerManager::updateControllerInfoLevel2_positions(UserInfo userInfo,
                                                       VehiclePositionsInfo &positionsInfo)
{

    // timeTest_2 ->recordInTime();
     RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
     if( rob  )
     {
         if((!rob->threadMotionEngine)
                 || (!rob->threadMotionEngine->mcControllerInterpreter)
                 || (!rob->programEngine)
                 || (!rob->programEngine->regData))
         {
             qDebug() << "***updateControllerInfoLevel2_positions*******point empty!!!!!!!!!!!\n\n"
                      << rob->threadMotionEngine
                      << rob->threadMotionEngine->mcControllerInterpreter
                      << rob->programEngine
                      << rob->programEngine->regData
                      <<endl;

             return 0;
         }


          //agv相关信息
          getVMarkPositionInWorld(userInfo,positionsInfo.vmarkInWorld);
          getVehiclePosition_specified(userInfo,6,positionsInfo.vehicleInVmark);
          getVehiclePosition_specified(userInfo,1,positionsInfo.vehicleInWorld);
          getVehiclePosition_specified(userInfo,9,positionsInfo.vehicleInQrcode);
          getVehiclePosition_specified(userInfo,10,positionsInfo.vehicleInCU1);


     }

     return 1;
     // timeTest_2 ->recordOutTime();
}

int PowerManager::updateControllerInfoLevel3(UserInfo userInfo, UpdateDataLv3 &updateDataLv3)
{
    static int iocount_x=0;

   // timeTest_3 ->recordInTime();
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
     if( rob)
     {
        globalManager->updateDataLevel3(updateDataLv3);

        if(rob->programEngine)//register
        {
            rob->programEngine->updateControllerInfoLevel3( updateDataLv3);
        }
         //Io模块
       // if(  rob->ioController->trylock() )
        {
            if(iocount_x<50){
                iocount_x++;
            }else{
                iocount_x=0;
//                printf("lv3333333:  di=%d do=%d si=%d so=%d ai=%d ao=%d\n",
//                       rob->ioController->diCount,
//                   rob->ioController->doCount,
//                   rob->ioController->siCount,
//                 rob->ioController->soCount,
//                 rob->ioController->aiCount,
//                rob->ioController->aoCount);
            }
            if(NULL!=rob->ioController)
            {
                rob->ioController-> updateLv3(
                        updateDataLv3.ioIn,
                       updateDataLv3.ioOut,
                         updateDataLv3.si,
                        updateDataLv3.so,
                        updateDataLv3.ai,
                       updateDataLv3.ao );
            }


//            updateDataLv3.si=rob->ioController->ioSi.toStdVector();
//            updateDataLv3.ai= rob->ioController->ioAi.toStdVector();
//            updateDataLv3.ioIn= rob->ioController->ioDi.toStdVector();
//            updateDataLv3.ioOut= rob->ioController->ioDo.toStdVector();
//            updateDataLv3.ao= rob->ioController->ioAo.toStdVector();
//            updateDataLv3.so= rob->ioController->ioSo.toStdVector();

           // rob->ioController->unlock();


        }
     }

    // timeTest_3 ->recordOutTime();
}

int PowerManager::getMotionServerInfo(UserInfo userInfo, UpdateDataLv2 &updateDataLv2)
{
    // timeTest_2 ->recordInTime();
     RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
     if( rob  )
     {
         if((!rob->threadMotionEngine)
                 || (!rob->threadMotionEngine->mcControllerInterpreter)
                 || (!rob->programEngine)
                 || (!rob->programEngine->regData))
         {
             qDebug() << "***getMotionServerInfo*******point empty!!!!!!!!!!!\n\n"
                      << rob->threadMotionEngine
                      << rob->threadMotionEngine->mcControllerInterpreter
                      << rob->programEngine
                      << rob->programEngine->regData
                      <<endl;

             return 0;
         }

         rob->threadMotionEngine->mcControllerInterpreter->updateControllerInfoLevel2( updateDataLv2 );

     }

     return 1;
}


int PowerManager::quickStopRobotMotor(int robotIdIn)
{
    robCtl->quickStopRobot( robotIdIn );
    return 1;
}

int PowerManager::updateControllerMessage( struct UserInfo userInfo, std::vector<struct Message> &messageVector)
{
    messageLog-> updateControllerInfoLevel2(  messageVector );
    return 0;//必须有
}

int PowerManager::initControllerStatus( struct UserInfo userInfo,int &controllerInitialStatusOut )
{

    if(  (eMasterOP == robCtl->getMasterState())
         ||(eMasterErr == robCtl->getMasterState()) )
    {
        controllerInitialStatusOut = 1;//ok
    }else{
         controllerInitialStatusOut = 0;
    }
    return 0;//必须有
}

int PowerManager::updateUserProgramFile(UserInfo userInfo, string fileName, string md5, int &returnFlag)
{
    if(disOPeratorPermission(userInfo))
    {
#ifdef MD5_CHECK
        //预留接口校验ｍｄ５值
        QString md5String = QString::fromStdString(md5);

        QString filePath = ROBOT_COMMON_NAME + QString::number(robotId) + ROBOT_PROGRAM_FLODER + QString::fromStdString(fileName);
        if(m_pMd5Instance->compareMd5(md5String,robotId))
        {
            //预留接口通过ｒｏｂｏｔＭａｎａｇｅｒ调用当前的机器人指针，调用程序解析引擎重新加载文件
            robotManager->robotsMap.value(robotId)->openFile(QString::fromStdString(fileName));
        }
        else
        {

        }
#else
        //预留接口通过ｒｏｂｏｔＭａｎａｇｅｒ调用当前的机器人指针，调用程序解析引擎重新加载文件
        robotManager->robotsMap.value(robotId)->openFile(QString::fromStdString(fileName));
#endif

        returnFlag = 0;
    }
    else
    {
        returnFlag = 1; //没有权限
    }
    return returnFlag;
}

int PowerManager::changePointType(UserInfo userInfo, PointPro inputPointPro, PointPro &pointPro)
{
    //如果普通用户可以进行该项操作的话，则不需要进行词句的判断，且returnFlag为０
    if(disOPeratorPermission(userInfo))
    {
        //     int jointFlag;                  //0:关节;1:笛卡尔;
        if(inputPointPro.jointFlag==JOINT_FLAG_JOINT )
        {
            pointPro=robotManager->robotsMap.value(robotId)->threadMotionEngine->mcControllerInterpreter -> pointCoordinateToCartesian( inputPointPro );
        }else{
            pointPro=robotManager->robotsMap.value(robotId)->threadMotionEngine->mcControllerInterpreter -> pointCoordinateToJoint( inputPointPro );
        }
        return 0;
    }
    else
    {
        return 1;   //没有权限
    }
}

int PowerManager::loginController_pchmi(UserInfo userInfo, string hmiVersion, int &returnFlag)
{
    qDebug()<<"PowerManager::loginController_pchmi account="<<userInfo.account<<",password= "<<
              QString::fromStdString(userInfo.password);
    int tmpKey=checkPcHmiVersion(hmiVersion);
    if(0>tmpKey)
    {
        returnFlag = -100;//版本不兼容，不允许登录
        addMsg( ENUM_MSG_WARNING,  "PowerManager", "PowerManager",  6028,  robotId);
        return returnFlag;
    }
    else if(0==tmpKey)
    {
        addMsg( ENUM_MSG_WARNING,  "PowerManager", "PowerManager",  6029,  robotId);
    }

    int returnKey=authority->loginIn(userInfo);
    if(1==returnKey)
    {
        returnFlag = 0;//登录成功
        return returnFlag;
    }
    else if(0==returnKey)
    {
        returnFlag = 0;//登录成功
        return returnFlag;
    }
    else
    {
        returnFlag = 1;//登录失败
        return returnFlag;
    }

    return returnFlag;
}

int PowerManager::loginController_webhmi(UserInfo userInfo, string hmiVersion, int &returnFlag)
{
    qDebug()<<"PowerManager::loginController_webhmi account="<<userInfo.account<<",password= "<<
              QString::fromStdString(userInfo.password);
    int tmpKey=checkWebHmiVersion(hmiVersion);
    if(0>tmpKey)
    {
        returnFlag = -100;//版本不兼容，不允许登录
        addMsg( ENUM_MSG_WARNING,  "PowerManager", "PowerManager",  6028,  robotId);
        return returnFlag;
    }
    else if(0==tmpKey)
    {
        addMsg( ENUM_MSG_WARNING,  "PowerManager", "PowerManager",  6029,  robotId);
    }

    int returnKey=authority->loginIn(userInfo);
    if(1==returnKey)
    {
        returnFlag = 0;//登录成功
        return returnFlag;
    }
    else if(0==returnKey)
    {
        returnFlag = 0;//登录成功
        return returnFlag;
    }
    else
    {
        returnFlag = 1;//登录失败
        return returnFlag;
    }

    return returnFlag;
}

int PowerManager::setDo(UserInfo userInfo, int ioOutNum, int nOffOn, int &returnFlag)
{
    //如果普通用户可以进行该项操作的话，则不需要进行词句的判断，且returnFlag为０
//    if(disOPeratorPermission(userInfo))
//    {

    bool tmpReturn=robotManager->robotsMap.value(robotId)->setCustomDo(ioOutNum,nOffOn);
        if(tmpReturn)
        {
            returnFlag = 0;

        }
            else
            {
            returnFlag = 1;
        }
//    }
//    else
//    {
//        //没有权限
//        returnFlag = 1;
//    }
        return returnFlag;
}

int PowerManager::setDi(UserInfo userInfo, int ioOutNum, int nOffOn, int &returnFlag)
{
    //如果普通用户可以进行该项操作的话，则不需要进行词句的判断，且returnFlag为０
//    if(disOPeratorPermission(userInfo))
//    {

    bool tmpReturn=robotManager->robotsMap.value(robotId)->setCustomDi(ioOutNum,nOffOn);
        if(tmpReturn)
        {
            returnFlag = 0;

        }
            else
            {
            returnFlag = 1;
        }
//    }
//    else
//    {
//        //没有权限
//        returnFlag = 1;
//    }
        return returnFlag;
}

int PowerManager::setSo(UserInfo userInfo, int ioOutNum, int nOffOn, int &returnFlag)
{
    bool tmpReturn=robotManager->robotsMap.value(robotId)->setSystemDo(ioOutNum,nOffOn);
        if(tmpReturn)
        {
            returnFlag = 0;

        }
            else
            {
            returnFlag = 1;
        }
    return returnFlag;
}

int PowerManager::setAo(UserInfo userInfo, int aoNum, double aoValue, int &returnFlag)
{
    qDebug()<<"PowerManager::setAo aoNum"<<aoNum<<"aoValue"<<aoValue;
    bool tmpReturn=robotManager->robotsMap.value(robotId)->setAo(aoNum,aoValue);
    if(tmpReturn)
    {
        returnFlag = 0;

    }
    else
    {
        returnFlag = 1;
    }
    return returnFlag;
}

int PowerManager::setManualSpeedPercent(UserInfo userInfo, float nSpeedValue, int &returnFlag)
{
//    if(disOPeratorPermission(userInfo))
//    {
        //预留接口通过ｒｏｂｏｔＭａｎａｇｅｒ调用当前的机器人指针，调用算法指针调用设置函数
        robotManager->robotsMap.value(robotId)->threadMotionEngine->mcControllerInterpreter->setManulSpeed( nSpeedValue );
        returnFlag=0;
//    }
//    else
//    {
//        //没有权限
//        returnFlag = 1;
//    }
    return returnFlag;
}

int PowerManager::setAutoSpeedPercent(UserInfo userInfo, float nSpeedValue, int &returnFlag)
{
//    if(authority->getAuthorityStatus()==ENUM_TIME_NORMAL)
//    {
//    if(disOPeratorPermission(userInfo))
//    {
        //预留接口通过ｒｏｂｏｔＭａｎａｇｅｒ调用当前的机器人指针，调用算法指针调用设置函数
        robotManager->robotsMap.value(robotId)->threadMotionEngine->mcControllerInterpreter->setAutoSpeed(nSpeedValue );
        returnFlag=0;
//    }
//    else
//    {
//        //没有权限
//        returnFlag = 1;
//    }
//    }
    return returnFlag;
}

int PowerManager::setHandWheel(UserInfo userInfo, int axisNumber, int direction, int velocity, int &returnFlag)
{
    if(disOPeratorPermission(userInfo))
    {
        //预留接口通过ｒｏｂｏｔＭａｎａｇｅｒ调用当前的机器人指针，调用算法指针调用设置函数
       // pointPro=robotManager->robotsMap.value(robotId)->threadMotionEngine->mcControllerInterpreter->setManulSpeed( nSpeedValue );
FUNTION_IS_EMPTY
    }
    else
    {
        //没有权限
        returnFlag = 1;
    }
}

int PowerManager::jogRun(UserInfo userInfo, int axisNumber, int direction, int &returnFlag)
{
    watchDog->startDog();
//    if(disOPeratorPermission(userInfo))
//    {
        //速度不需要传递，内部自动转换， jog（）， 0=当前设定速度执行， 1=滚轮速度
        robotManager->robotsMap.value(robotId)->threadMotionEngine->mcControllerInterpreter->jog(
                    axisNumber,
                    direction,
                    0
                    );
        qDebug()<<"PowerManager::jogRun-----------------------------------";
        returnFlag = 0;
//    }
//    else
//    {
//        //没有权限
//        returnFlag = 1;
//    }
    return returnFlag;
}

int PowerManager::setProgramFileName(UserInfo userInfo, string programFileName, int &returnFlag)
{
    if(disOPeratorPermission(userInfo))
    {

    }
    else
    {
        //没有权限
        returnFlag = 1;
    }

        RobotEngine* robot=robotManager->robotsMap.value(robotId, NULL );
        if( robot && robot->programEngine && (robot->programEngine->getEngineStatue()) != ENUM_RUN )
        {
            robot->openFile(QString::fromStdString(programFileName));
            returnFlag=0;
        }else{
            returnFlag = 2;
        }

       if( returnFlag==2 ){
//           QString msg=QObject::tr( "正在运动中 ! ");
           addMsg( ENUM_MSG_REMIND,  "PowerManager", "PowerManager",  6000,  robotId);
       }else   if( returnFlag==1 ){
//           QString msg=QObject::tr( "用户权限不足! ");
//           addMsg( ENUM_MSG_REMIND,  "PowerManager", "PowerManager",  6001,  robotId);
       }
       //else  执行操作

       return returnFlag;
}

int PowerManager::setProgramFileName_fleet(string programFileName)
{
    int returnFlag;

        RobotEngine* robot=robotManager->robotsMap.value(robotId, NULL );
        if( robot && robot->programEngine && (robot->programEngine->getEngineStatue()) != ENUM_RUN )
        {
            robot->openFile(QString::fromStdString(programFileName));
            returnFlag=0;
        }else{
            returnFlag = 2;
        }

       if( returnFlag==2 ){
//           QString msg=QObject::tr( "正在运动中 ! ");
           addMsg( ENUM_MSG_REMIND,  "PowerManager", "PowerManager",  6000,  robotId);
       }else   if( returnFlag==1 ){
//           QString msg=QObject::tr( "用户权限不足! ");
//           addMsg( ENUM_MSG_REMIND,  "PowerManager", "PowerManager",  6001,  robotId);
       }
       //else  执行操作

       return returnFlag;
}

int PowerManager::setProgramRunLine(UserInfo userInfo, int line, int &returnFlag)
{
    if(disOPeratorPermission(userInfo))
    {
        //预留接口通过ｒｏｂｏｔＭａｎａｇｅｒ调用当前的机器人指针，调用机器人解析引擎指针调用设置函数
        robotManager->robotsMap.value(robotId)->programEngine->setStartLine(line);
        returnFlag = 0;
    }
    else
    {
        //没有权限
        returnFlag = 1;
    }
    return returnFlag;
}

int PowerManager::setRunModel(UserInfo userInfo, int runModel, int &returnFlag)
{

    if(1==robotManager->robotsMap.value(robotId)->setRunModel((EN_CONTROL_TYPE)runModel))
    {

       returnFlag = 0;
    }
    else
    {
        returnFlag = 1;
    }


    return returnFlag;
}

int PowerManager::setAllRunModel(UserInfo userInfo, int runModel, int &returnFlag)
{
    RobotEngine* robotEngine;
    foreach ( robotEngine, robotManager->robotsMap )
    {
        if( robotEngine )
        {
            if(1!=robotEngine->setRunModel((EN_CONTROL_TYPE)runModel))
            {
                return -1;
            }
        }
    }
    return 1;
}

int PowerManager::setDebugModel(UserInfo userInfo, int debugModel, int &returnFlag)
{
//    if(disOPeratorPermission(userInfo))
//    {
        if( (robotManager->robotsMap.value(robotId)->programEngine->getEngineStatue()) != ENUM_COMMAND_RUN  )
        {
            robotManager->robotsMap.value(robotId)->programEngine->setMoveType(debugModel);
            returnFlag = 0;
        }else{
            returnFlag = 2;
        }
//    }
//    else
//    {
//        //没有权限
//        returnFlag = 1;
//    }

    if( returnFlag==2 )
    {
        addMsg(ENUM_MSG_REMIND,  "PowerManager", "PowerManager",  6000,  robotId ,  0, 0, 0 );
    }else   if( returnFlag==1 ){
//        addMsg(ENUM_MSG_REMIND,  "PowerManager", "PowerManager",  6001,  robotId ,  0, 0, 0 );
    }
    return returnFlag;
}

int PowerManager::setJogCoordinator(UserInfo userInfo, int coordinator, int &returnFlag)
{
    if(disOPeratorPermission(userInfo))
    {
        //预留接口通过ｒｏｂｏｔＭａｎａｇｅｒ调用当前的机器人指针，调用算法指针调用设置函数
        robotManager->robotsMap.value(robotId)->threadMotionEngine->mcControllerInterpreter->setJogCoordinate( coordinator );
        returnFlag=0;
    }
    else
    {
//        addMsg( ENUM_MSG_REMIND,  "PowerManager", "PowerManager",  6001,  robotId);
        //没有权限
        returnFlag = 1;
    }
    return returnFlag;
}

int PowerManager::moveToPoint(UserInfo userInfo, MoveParameter moveParameter, int &returnFlag)
{
//    if(disOPeratorPermission(userInfo))
//    {
        qDebug()<< "PowerManager::moveToPoint 移动到点..";
        if( robotManager->robotsMap.value(robotId)->threadMotionEngine->mcControllerInterpreter
                && robotManager->robotsMap.value(robotId)->threadMotionEngine
                ->mcControllerInterpreter->getStatus() !=ENUM_RUN )
        {
            robotManager->robotsMap.value(robotId)->threadMotionEngine
                    ->mcControllerInterpreter->moveToPoint( moveParameter);
            returnFlag=0;
        }else{
            returnFlag=2;
        }
//    }
//    else
//    {
//        //没有权限
//        returnFlag = 1;
//    }

    if( returnFlag==2 ){
        addMsg( ENUM_MSG_REMIND,  "PowerManager", "PowerManager",  6000,  robotId ,  0, 0, 0 );
    }else   if( returnFlag==1 ){
//        addMsg( ENUM_MSG_REMIND,  "PowerManager", "PowerManager",  6001,  robotId ,  0, 0, 0  );
    }
    //else  执行操作

    return returnFlag;
}

int PowerManager::programRun(UserInfo userInfo, int &returnFlag)
{
    return programOneRun(userInfo,robotId,returnFlag);
}

int PowerManager::programRun_fleet()
{
    int returnFlag;
    //enableRun
    if(false==enableRun[0] ||false==enableRun[0] ||false==enableRun[0] ||false==enableRun[0] )
    {
        returnFlag =2;
        qDebug()<<"programRun error,false==enableRun[0] ||false==enableRun[0] ||false==enableRun[0] ||false==enableRun[0] ";
        addMsg( ENUM_MSG_ERROR,  "PowerManager", "PowerManager",  6022,  robotId  );
        return returnFlag;
    }
    returnFlag=checkAuthority_run();
    if(1!=returnFlag)
    {
        return returnFlag;
    }

    if( robotManager->robotsMap.value(robotId)->programEngine
            && (robotManager->robotsMap.value(robotId)->programEngine->getEngineStatue()) !=ENUM_RUN )
     {
         returnFlag = 0;    //预留接口通过ｒｏｂｏｔＭａｎａｇｅｒ调用当前的机器人指针，调用机器人解析引擎指针调用设置函数
         //robotManager->robotsMap.value(robotId)->programEngine->runProgram();//錯誤的做法
         robotManager->robotsMap.value(robotId)->runProgram();//
     }
    else
    {
         returnFlag = 2;
     }

    if( returnFlag==2 )
    {
        addMsg( ENUM_MSG_ERROR,  "PowerManager", "PowerManager",  6000,  robotId ,  0, 0, 0);
    }
    else   if( returnFlag==1 ){
        addMsg( ENUM_MSG_REMIND,  "PowerManager", "PowerManager",  6001,  robotId ,  0, 0, 0 );
    }
    //else  执行操作

    return returnFlag;
}

int PowerManager::programOneRun(UserInfo userInfo, int robotIdIn, int &returnFlag)
{
    //enableRun
    if(false==enableRun[0] ||false==enableRun[0] ||false==enableRun[0] ||false==enableRun[0] )
    {
        returnFlag =2;
        qDebug()<<"programRun error,false==enableRun[0] ||false==enableRun[0] ||false==enableRun[0] ||false==enableRun[0] ";
        addMsg( ENUM_MSG_ERROR,  "PowerManager", "PowerManager",  6022,  robotId  );
        return returnFlag;
    }
    returnFlag=checkAuthority_run();
    if(1!=returnFlag)
    {
        return returnFlag;
    }

    if( robotManager->robotsMap.value(robotId)->programEngine
            && (robotManager->robotsMap.value(robotIdIn)->programEngine->getEngineStatue()) !=ENUM_RUN )
     {
         returnFlag = 0;    //预留接口通过ｒｏｂｏｔＭａｎａｇｅｒ调用当前的机器人指针，调用机器人解析引擎指针调用设置函数
         //robotManager->robotsMap.value(robotId)->programEngine->runProgram();//錯誤的做法
         robotManager->robotsMap.value(robotIdIn)->runProgram();//
     }
    else
    {
         returnFlag = 2;
     }

    if( returnFlag==2 )
    {
       // addMsg( ENUM_MSG_ERROR,  "PowerManager", "PowerManager",  6000,  robotIdIn ,  0, 0, 0);
    }
    else   if( returnFlag==1 ){
//        addMsg( ENUM_MSG_REMIND,  "PowerManager", "PowerManager",  6001,  robotId ,  0, 0, 0 );
    }
    //else  执行操作

    return returnFlag;
}

int PowerManager::programAllRun(UserInfo userInfo, int &returnFlag)
{
    RobotInfo* robotInfo;

    foreach ( robotInfo, robotManager->robotsInfoMap )
    {
        if( robotInfo )
        {
            programOneRun(userInfo,robotInfo->robotId,returnFlag);
        }
    }
    return 1;
}

int PowerManager::checkAuthority_run()
{
    int returnFlag=1;
    //文件不存在时，不允许运行
    if(authority->getAuthorityStatus() == ENUM_REGISTER_FILE_NO_EXIST
            ||ENUM_REGISTER_FILE_NODE_ERROR==authority->getAuthorityStatus()
            ||ENUM_REGISTER_FILE_CHECK_CODE_ERROR==authority->getAuthorityStatus())
    {
        returnFlag =2;
        qDebug()<<"programRun error,registerType == ENUM_REGISTER_FILE_NO_EXIST ||ENUM_REGISTER_FILE_NODE_ERROR==registerType  ||ENUM_REGISTER_FILE_CHECK_CODE_ERROR==registerType";
        addMsg( ENUM_MSG_ERROR,  "PowerManager", "PowerManager",  6011,  robotId  );
        return returnFlag;
    }
    else if(authority->getAuthorityStatus() == ENUM_TIME_PASSED)
    {
        returnFlag =2;
        qDebug()<<"programRun error,registerType == ENUM_TIME_PASSED";
        addMsg( ENUM_MSG_ERROR,  "PowerManager", "PowerManager",  6024,  robotId  );
        return returnFlag;
    }
    else if(authority->getAuthorityStatus() == ENUM_TIME_GOING_PASSED)
    {
        qDebug()<<"programRun warn,registerType == ENUM_TIME_PASSED";
        addMsg( ENUM_MSG_WARNING,  "PowerManager", "PowerManager",  6025,  robotId  );
        return 1;
    }

    if(ENUM_TIME_GOING_PASSED!=authority->getAuthorityStatus() && ENUM_TIME_NORMAL!=authority->getAuthorityStatus() )
    {
        addMsg( ENUM_MSG_WARNING,  "PowerManager", "PowerManager",  6026,  robotId  );
        return 1;
    }
    return 1;
}

int PowerManager::programCease(UserInfo userInfo, int &returnFlag)
{

    //预留接口通过ｒｏｂｏｔＭａｎａｇｅｒ调用当前的机器人指针，调用机器人解析引擎指针调用设置函数
    //判断调度模式
//    if(ENUM_CONTROL_FLEET==p_powerManger->getRunModel())
//    {
//        motion_allCease();
//    }
//    else
//    {
        robotManager->robotsMap.value(robotId)->ceaseProgram();
//    }


    returnFlag = 0;
    return returnFlag;
}

int PowerManager::programCease_fleet()
{
    return robotManager->robotsMap.value(robotId)->ceaseProgram();
}

int PowerManager::programAllCease(UserInfo userInfo, int &returnFlag)
{
    RobotEngine* robotEngine;
    foreach ( robotEngine, robotManager->robotsMap )
    {
        if( robotEngine )
        {
            robotEngine->ceaseProgram();
        }
    }
    return 1;
}

int PowerManager::quickStop(UserInfo userInfo, int &returnFlag)
{
    RobotEngine* robotEngine;
    foreach ( robotEngine, robotManager->robotsMap )
    {
        if( robotEngine )
        {
            robotEngine->quickStop();
        }
    }
    return 1;
}

int PowerManager::stopRobotEngine(int robotIdIn)
{

     quickStopRobotMotor(robotIdIn);
     RobotEngine* robotEngine;
     if( robotIdIn<0  )
     {
         foreach ( robotEngine, robotManager->robotsMap )
         {
             if( robotEngine ){
                 robotEngine->resetProgram();
             }
         }
     }
     else if(robotIdIn<robotManager->robotsMap.size())
     {

      robotManager->robotsMap.value(robotIdIn)->resetProgram();
     }
     else
     {
         qDebug()<<"robotId超过合理范围！";
         addMsg( ENUM_MSG_REMIND,  "PowerManager", "PowerManager",  6020,  robotId);
     }
      watchDog->resetDog();
      return 1;
}


bool PowerManager::isCurrentRobotServoOn()
{
    return isRobotServoOn(robotId);
}

bool PowerManager::isRobotServoOn(int robotIdIn)
{
     RobotEngine* robotEngine;
     if( robotIdIn<0  )
     {
         foreach ( robotEngine, robotManager->robotsMap )
         {
             if( robotEngine ){
                 if(true==robotEngine->threadMotionEngine->mcControllerInterpreter->isServoOn())
                 {
                     return true;
                 }

             }
         }
     }
      return robotManager->robotsMap.value(robotId)->threadMotionEngine->mcControllerInterpreter->isServoOn();

}

int PowerManager::getCurrentRobotBasicStatus()
{
    getRobotBasicStatus(robotId);
}

int PowerManager::getRobotBasicStatus(int robotIdIn)
{
     RobotEngine* robotEngine;
     if( robotIdIn<0  )
     {
         foreach ( robotEngine, robotManager->robotsMap )
         {
             if( robotEngine ){
                 if(ENUM_COMMAND_RUN==robotEngine->getRobotBasicStatus())
                 {
                     return ENUM_COMMAND_RUN;
                 }

             }
         }
     }
     if(NULL==robotManager->robotsMap.value(robotId))
     {
        return ENUM_COMMAND_RESET;
     }

      return robotManager->robotsMap.value(robotId)->getRobotBasicStatus();

}





int PowerManager::programReset(UserInfo userInfo, int &returnFlag)
{
    watchDog->resetDog();
    if(NULL==robotManager->robotsMap.value(robotId))
    {
        returnFlag = 0;
       return returnFlag;
    }
    //判断调度模式
//    if(ENUM_CONTROL_FLEET==p_powerManger->getRunModel())
//    {
//        p_powerManger->motion_allCease();
//    }
//    else
//    {
        robotManager->robotsMap.value(robotId)->resetProgram();
//    }


    returnFlag = 0;
    return returnFlag;
}

int PowerManager::programReset_fleet()
{
    watchDog->resetDog();
    if(NULL==robotManager->robotsMap.value(robotId))
    {
       return 0;
    }
    return robotManager->robotsMap.value(robotId)->resetProgram();

}

int PowerManager::programAllReset(UserInfo userInfo, int &returnFlag)
{
    RobotEngine* robotEngine;
    foreach ( robotEngine, robotManager->robotsMap )
    {
        if( robotEngine )
        {
            //判断调度模式
//            if(ENUM_CONTROL_FLEET==p_powerManger->getRunModel())
//            {
//                motion_allCease();
//            }
//            else
//            {
                robotEngine->resetProgram();
//            }

        }
    }
    return 1;
}

int PowerManager::returnZeroPoint(UserInfo userInfo, int axisNumber, int &returnFlag)
{
    qDebug() << __FUNCTION__<<"=-====out===="<<axisNumber<<"\n\n\n\n"<<endl;
    if(disOPeratorPermission(userInfo))
    {
        RobotEngine* rob= robotManager->robotsMap.value( robotId ,NULL);
        if( rob )
        {
            robotManager->robotsMap.value(robotId)->threadMotionEngine->mcControllerInterpreter->returnZeroPoint(axisNumber,returnFlag);
            returnFlag=0;
        }
    }
    else
    {
//        addMsg( ENUM_MSG_REMIND,  "PowerManager", "PowerManager",  6001,  robotId);
        //没有权限
        returnFlag = 1;
    }
    return returnFlag;
}

int PowerManager::returnZeroPoint(UserInfo userInfo, int &returnFlag)
{

    if(disOPeratorPermission(userInfo))
    {
        robotManager->robotsMap.value(robotId)->threadMotionEngine->mcControllerInterpreter->returnZeroPoint(-1,returnFlag);
        returnFlag=0;
    }
    else
    {
        //没有权限
        returnFlag = 1;
    }
    return returnFlag;
}

int PowerManager::controllerShutDown()
{

    return globalManager->controllerShutDown();

}

int PowerManager::writePathMovingInfo()
{
    if(false==robotManager->robotsMap.contains(robotId))
    {
        return -1;
    }
    RobotEngine* rob = robotManager->robotsMap.value( robotId, NULL );
    if( NULL==rob  )
    {
        return -1;
    }
    if((!rob->threadMotionEngine)
                || (!rob->threadMotionEngine->mcControllerInterpreter)
                || (!rob->programEngine)
                || (!rob->programEngine->regData))
    {
        return -1;
    }


    return rob->threadMotionEngine->mcControllerInterpreter->writePathMovingInfo();
}

int PowerManager::controlShutDownEnable(UserInfo userInfo, bool enable,int &returnFlag)
{
    if(disOPeratorPermission(userInfo))
    {
        globalManager->controlShutDownEnable(enable);
        returnFlag=0;
    }
    else
    {
        //没有权限
        returnFlag = 1;
    }
    return returnFlag;
}

int PowerManager::controllerShutDown(UserInfo userInfo, int &returnFlag)
{
    if(disOPeratorPermission(userInfo))
    {
        returnFlag=globalManager->controllerShutDown();

    }
    else
    {
        //没有权限
        returnFlag = -2;
    }
    return returnFlag;
}

int PowerManager::controllerShutDownAndReboot(UserInfo userInfo, int &returnFlag)
{
    if(disOPeratorPermission(userInfo))
    {
        globalManager->controllerShutDown(true);
        returnFlag=0;
    }
    else
    {
        //没有权限
        returnFlag = 1;
    }
    return returnFlag;
}

int PowerManager::setManualServon(UserInfo userInfo, int nServOffOn, int &returnFlag)
{
//    if(disOPeratorPermission(userInfo))
//    {
        if( globalManager==NULL|| robotManager==NULL )
        {
            returnFlag = 2;
            return returnFlag;
        }

        if(ENUM_SERVO_OFF == nServOffOn)
        {
            robotManager->robotsMap.value(robotId)->threadMotionEngine->mcControllerInterpreter->servoOff();
        }
        else if(ENUM_SERVO_ON == nServOffOn)
        {

            robotManager->robotsMap.value(robotId)->threadMotionEngine->mcControllerInterpreter->servoOn();

        }

        returnFlag = 0;
//    }
//    else
//    {
//        //没有权限
//        returnFlag = 1;
//    }
        return returnFlag;
}

int PowerManager::setAllManualServon(UserInfo userInfo, int nServOffOn, int &returnFlag)
{

    //    if(disOPeratorPermission(userInfo))
    //    {
            if( globalManager==NULL|| robotManager==NULL )
            {
                returnFlag = 2;
                return returnFlag;
            }

            if(ENUM_SERVO_OFF == nServOffOn)
            {
                servoOnAllRobot();
            }
            else if(ENUM_SERVO_ON == nServOffOn)
            {

                servoOffAllRobot();

            }

            returnFlag = 0;
    //    }
    //    else
    //    {
    //        //没有权限
    //        returnFlag = 1;
    //    }
            return returnFlag;
}

int PowerManager::servoOffCurrentRobot()
{
    robotManager->robotsMap.value(robotId)->threadMotionEngine->mcControllerInterpreter->servoOff();
    return 1;
}

int PowerManager::servoOnCurrentRobot()
{
    qDebug()<<"PowerManager::servoOnCurrentRobot";
    return robotManager->robotsMap.value(robotId)->threadMotionEngine->mcControllerInterpreter->servoOn();
    return 1;
}

int PowerManager::servoOffAllRobot()
{
    RobotEngine* robotEngine;
    foreach ( robotEngine, robotManager->robotsMap )
    {
        if( robotEngine )
        {
            robotEngine->threadMotionEngine->mcControllerInterpreter->servoOff();
        }
    }
    return 1;
}

int PowerManager::servoOnAllRobot()
{
    RobotEngine* robotEngine;
    foreach ( robotEngine, robotManager->robotsMap )
    {
        if( robotEngine )
        {
            robotEngine->threadMotionEngine->mcControllerInterpreter->servoOn();
        }
    }
    return 1;
}

int PowerManager::servoOnrobot(int robotIdIn)
{
    robotManager->robotsMap.value(robotIdIn)->threadMotionEngine->mcControllerInterpreter->servoOn();
    return 1;
}

int PowerManager::setSafeSpeedRatio(double safeSpeedRatioIn, double time)
{
    return robotManager->robotsMap.value(robotId)->threadMotionEngine
            ->mcControllerInterpreter->setSafeSpeedRatio(safeSpeedRatioIn,time);
}

int PowerManager::setAllSafeSpeedRatio(double safeSpeedRatioIn, double time)
{
    RobotInfo* robotInfo;

    foreach ( robotInfo, robotManager->robotsInfoMap )
    {
        if( robotInfo )
        {
            robotManager->robotsMap.value(robotInfo->robotId)->threadMotionEngine
                        ->mcControllerInterpreter->setSafeSpeedRatio(safeSpeedRatioIn,time);
        }
    }
    return 1;
}



int PowerManager::setRegisterNumber(UserInfo userInfo, string registerString, ReturnRegisterStatus &returnStatus)
{
    int returnFlag = 1;
    if(disOPeratorPermission(userInfo))
    {
        authority->setRegisterNumber(registerString,returnStatus);
        returnFlag = 0;
    }
    else
    {
         returnFlag = 1; //没有权限
    }

    return returnFlag;
}

int PowerManager::getTcpConnectState(UserInfo userInfo, int &returnFlag)
{
    //判断断线、链接状态
    returnFlag = 1;             //= EM_CONNECT_SUCCESS
}

int PowerManager::setClearAllCounter(UserInfo userInfo, int &returnFlag)
{
    //清除所有产量
    if(disOPeratorPermission(userInfo))
    {
        FUNTION_IS_EMPTY
           //     returnFlag=0;
    }
    else
    {
         returnFlag = 1; //没有权限
    }
    return returnFlag;

}

int PowerManager::setClearCurrentCounter(UserInfo userInfo, int &returnFlag)
{
    //清除当前产量
    if(disOPeratorPermission(userInfo))
    {
        FUNTION_IS_EMPTY
                //        robotManager->robotsMap.value(robotId)->threadMotionEngine->mcControllerInterpreter->moveToPoint( coordinator );
           //     returnFlag=0;
    }
    else
    {
         returnFlag = 1; //没有权限
    }
    return returnFlag;
}

int PowerManager::setRestoreFactory(UserInfo userInfo, int &returnFlag)
{
    //通知控制器重新启动，ｈｍｉ控制文件的解压覆盖并通知控制器重新启动
    if(disOPeratorPermission(userInfo))
    {

    }
    else
    {
         returnFlag = 1; //没有权限
    }
}

int PowerManager::setCoordMode(UserInfo userInfo, int nCoordId, int &returnFlag)
{
    //切换坐标系、算法
    if(disOPeratorPermission(userInfo))
    {
        robotManager->robotsMap.value(robotId)->threadMotionEngine->mcControllerInterpreter->setJogCoordinate( nCoordId );
        returnFlag=0;
    }
    else
    {
         returnFlag = 1; //没有权限
    }
    return returnFlag;
}

int PowerManager::setAllMsgClear(struct UserInfo userInfo,int &returnFlag)
{
    qDebug()<<"PowerManager::setAllMsgClear";
    //清除消息
//    if(disOPeratorPermission(userInfo))
//    {
     //   resetErrorRobot( robotId );

//    if( eMasterErr == robCtl->getMasterState()
//            ||eMasterOP == robCtl->getMasterState() )

        if(messageLog->isErrorOccured())
        {
            robCtl->resetErrorRobot( -1 );
            robotManager->robotsMap.value(robotId)->clearAllMsg();
            robotManager->robotsMap.value(robotId)->threadMotionEngine
                                ->mcControllerInterpreter->clearAllMsg();
        }

       returnFlag = 0;

       QVector <Message> allMsgList;
       messageLog->getAllMessage(allMsgList);
       for(int i=0;i<allMsgList.size(); i++)
       {
           Message powerMsg = allMsgList.at(i);
           if( "EcatMaster" == powerMsg.componentClassName )
           {
               if( 31== powerMsg.messageCode )
                   returnFlag = 0;//wkc
               else
                   returnFlag = -1; //主站的错误请不掉的，只能改配置或者重启
           }
       }
       if( messageLog )
       {
           messageLog->clearAllMessage();
       }
       return returnFlag;
//    }
//    else
//    {

//        returnFlag = 1; //没有权限
       //    }
}

int PowerManager::setAllMsgClear_fleet()
{
    int returnFlag;
    robCtl->resetErrorRobot( -1 );

    if( messageLog )
    {
        messageLog->clearAllMessage();
    }


   robotManager->robotsMap.value(robotId)->clearAllMsg ();
   robotManager->robotsMap.value(robotId)->threadMotionEngine
            ->mcControllerInterpreter->clearAllMsg ();

   returnFlag = 0;

   QVector <Message> allMsgList;
   messageLog->getAllMessage(allMsgList);
   for(int i=0;i<allMsgList.size(); i++)
   {
       Message powerMsg = allMsgList.at(i);
       if( "EcatMaster" == powerMsg.componentClassName )
       {
           if( 31== powerMsg.messageCode )
               returnFlag = 0;//wkc
           else
               returnFlag = -1; //主站的错误请不掉的，只能改配置或者重启
       }
   }
   return returnFlag;
}

int PowerManager::setMsgClear(UserInfo userInfo, int messageId, int &returnFlag)
{
    //清除消息
//    if(disOPeratorPermission(userInfo))
//    {
//        int clearFlag = -1;//清除标志位，返回０标示可以清除，－１标示不能清除
        int clearFlag = 0;

        robotManager->robotsMap.value(robotId)->clearAllMsg();
        QVector <Message> allMsgList;
        messageLog->getAllMessage(allMsgList);
        if(messageId < allMsgList.size())
        {
            Message powerMsg = allMsgList[messageId];
            string powerComponentName = powerMsg.componentClassName;

            if( powerMsg.robotId>0 ){
                if( (eMasterErr == robCtl->getMasterState())
                        ||(eMasterOP == robCtl->getMasterState()) )
                    clearFlag = robCtl->clearMessage(powerMsg);
            }

            if( "EcatMaster" == powerComponentName )
            {
                if( 31== powerMsg.messageCode )
                    clearFlag = 0;//wkc
                else
                    clearFlag = -1; //主站的错误请不掉的，只能改配置或者重启
            }
            else
            if("Coordinate" == powerComponentName)
            {

            }
            else if("DomParser" == powerComponentName)
            {

            }
            else if("GlobalManager" == powerComponentName)
            {

            }
            else if("InternalSafe" == powerComponentName)
            {

            }
            else if("IoController" == powerComponentName)
            {

            }
            else if("JointDecouple" == powerComponentName)
            {

            }
            else if("McControllerInterpreter" == powerComponentName)
            {
                clearFlag= robotManager->robotsMap.value(robotId)->threadMotionEngine
                        ->mcControllerInterpreter->clearMsg ( powerMsg );
            }
            else if("MD5Check" == powerComponentName)
            {

            }
            else if("MotorInterface" == powerComponentName)
            {

            }
            else if("PalletCalculate" == powerComponentName)
            {

            }
            else if("PointData" == powerComponentName)
            {

            }
            else if("ProgramEngine" == powerComponentName)
            {

            }
            else if("RegData" == powerComponentName)
            {

            }
            else if("RobotEngine" == powerComponentName)
            {

            }
            else if("RobotManager" == powerComponentName)
            {

            }
            else if("TrajectoryScale" == powerComponentName)
            {

            }
            else if("XmlParse" == powerComponentName)
            {

            }
            else if("PowerManager" == powerComponentName)
            {
                qDebug() <<"=======emergency=====stop======="<<"\n\n";
                clearFlag= robotManager->robotsMap.value(robotId)->threadMotionEngine
                        ->mcControllerInterpreter->clearMsg ( powerMsg );
            }

            if(0 == clearFlag)
            {
                messageLog->clearMessage(messageId);
            }

            returnFlag = 0;

        }
        else
        {
            returnFlag = -1;
        }

        return returnFlag;
//    }
//    else
//    {
//         returnFlag = 1; //没有权限
//    }
}

int PowerManager::setRobotSingleAxisCaliberate(UserInfo userInfo, int axisId, int &returnFlag)
{
    //单轴零点标定
    if(disOPeratorPermission(userInfo))
    {
        //预留接口通过ｒｏｂｏｔＭａｎａｇｅｒ调用当前的机器人指针，调用机器人解析引擎指针调用设置函数
        returnFlag =robotManager->robotsMap.value(robotId)->threadMotionEngine->mcControllerInterpreter->calibrateRobot(axisId);
        qDebug()<<"success:  PowerManager::setSingleCaliber, robotId="<<robotId<<returnFlag;

    }
    else
    {
         returnFlag = -1; //没有权限
    }
    return returnFlag;
}

int PowerManager::setRobotAllAxisCaliberate(UserInfo userInfo,int &returnFlag)
{

    if(disOPeratorPermission(userInfo))
    {
        RobotEngine* rob = robotManager->robotsMap.value(robotId, NULL);
        if(!rob)
        {
            qDebug()<<"Error: 零点标定失败,机器人ID错误:"<<robotId;
            returnFlag=-1;
            return 1;
        }

       returnFlag = rob->threadMotionEngine->mcControllerInterpreter->calibrateRobot();
       qDebug()<<"success:  PowerManager::setAllCaliber, robotId="<<robotId<<returnFlag;
    }
    else
    {
         returnFlag = -2; //没有权限
    }
    return returnFlag;
}

int PowerManager::getCalibrateInformation(UserInfo userInfo,
                                          S_AXISGROUP_ZERO_INFORMATION &zeroInformationOut)
{
    if(disOPeratorPermission(userInfo))
    {
        RobotEngine* rob = robotManager->robotsMap.value(robotId, NULL);
        if(!rob)
        {
            qDebug()<<"Error: getCalibrateInformation失败,机器人ID错误:"<<robotId;

            return 1;
        }

       rob->threadMotionEngine->mcControllerInterpreter->getCalibrateInformation(zeroInformationOut);
       qDebug()<<"success:  PowerManager::getCalibrateInformation, robotId="<<robotId;


    }
    else
    {
         return -1; //没有权限
    }
    return 1;
}

int PowerManager::clearPlRegister(UserInfo userInfo, int palletNumber, int &returnFlag)
{
    if(disOPeratorPermission(userInfo))
    {
        //预留接口通过ｒｏｂｏｔＭａｎａｇｅｒ调用当前的机器人指针，调用机器人解析引擎指针调用设置函数
        robotManager->robotsMap.value(robotId)->programEngine->regData->clearPlReg(palletNumber);
        returnFlag = 0;
    }
    else
    {
        returnFlag = 1; //没有权限
    }
    return returnFlag;
}

int PowerManager::clearAllPlRegister(UserInfo userInfo, int &returnFlag)
{
    if(disOPeratorPermission(userInfo))
    {
        //预留接口通过ｒｏｂｏｔＭａｎａｇｅｒ调用当前的机器人指针，调用机器人解析引擎指针调用设置函数
        robotManager->robotsMap.value(robotId)->programEngine->regData->clearAllPlValue();
        returnFlag = 0;
    }
    else
    {
        returnFlag = 1; //没有权限
    }
    return returnFlag;
}

int PowerManager::setPlRegister(UserInfo userInfo, int palletNumber, PlRegStruct plReg, int &returnFlag)
{
    if(disOPeratorPermission(userInfo))
    {

         robotManager->robotsMap.value(robotId)->programEngine->setPlRegister(palletNumber,plReg,returnFlag);

    }
    else
    {

    }
    return returnFlag;
}


int PowerManager::setLocalRegister(UserInfo userInfo, int number, double value, int &returnFlag)
{
    if(disOPeratorPermission(userInfo))
    {
        //预留接口通过ｒｏｂｏｔＭａｎａｇｅｒ调用当前的机器人指针，调用机器人解析引擎指针调用设置函数

        robotManager->robotsMap.value(robotId)->programEngine->regData->setRRegValue(number,value);
        returnFlag = 0;
    }
    else
    {

    }
    return returnFlag;
}

int PowerManager::setLocalPrRegister(UserInfo userInfo, int number, PointPro point,int &returnFlag)
{
    if(disOPeratorPermission(userInfo))
    {
        //预留接口通过ｒｏｂｏｔＭａｎａｇｅｒ调用当前的机器人指针，调用机器人解析引擎指针调用设置函数
        robotManager->robotsMap.value(robotId)->programEngine->regData->setPrRegValue(number,point);
        returnFlag = 0;
    }
    else
    {

    }
    return returnFlag;
}

int PowerManager::clearAllLocalRegister(UserInfo userInfo, int &returnFlag)
{
    if(disOPeratorPermission(userInfo))
    {
        //预留接口通过ｒｏｂｏｔＭａｎａｇｅｒ调用当前的机器人指针，调用机器人解析引擎指针调用设置函数

        robotManager->robotsMap.value(robotId)->programEngine->regData->clearAllRegRValue();
        returnFlag = 0;
    }
    else
    {
        returnFlag = 1; //没有权限
    }
    return returnFlag;
}


int PowerManager::clearAllRobotsAllRegister(UserInfo userInfo,int &returnFlag)
{

    if(disOPeratorPermission(userInfo))
    {
        globalManager->clearAllRobotsAllRegister(returnFlag);
    }
    else
    {
        returnFlag = 1; //没有权限
    }
    return returnFlag;

}

int PowerManager::clearCurrentRobotAllRegister(UserInfo userInfo,int &returnFlag)
{
    if(disOPeratorPermission(userInfo))
    {
        clearAllGlobalRegister(userInfo,returnFlag);
        clearAllPrRegister(userInfo,returnFlag);
        clearAllTimerRegister(userInfo,returnFlag);
        clearAllLocalRegister(userInfo,returnFlag);
        clearAllPlRegister(userInfo,returnFlag);
        returnFlag = 0;
    }
    else
    {
        returnFlag = 1; //没有权限
    }
    return returnFlag;

}

int PowerManager::setGlobalRegister(UserInfo userInfo, int number, double value, int &returnFlag)
{
    if(disOPeratorPermission(userInfo))
    {
        globalManager->saveRegRValue(number,value);
        returnFlag = 0;
    }
    else
    {
        returnFlag = 1; //没有权限
    }
    return returnFlag;
}

int PowerManager::clearAllGlobalRegister(UserInfo userInfo, int &returnFlag)
{
    if(disOPeratorPermission(userInfo))
    {
        globalManager->clearRegRValue();
    }
    else
    {
        returnFlag = 1; //没有权限
    }
    return returnFlag;
}

int PowerManager::clearAllPrRegister(UserInfo userInfo, int &returnFlag)
{
    if(disOPeratorPermission(userInfo))
    {
        robotManager->robotsMap.value(robotId)->programEngine->regData->clearAllPrValue();
    }
    else
    {
        returnFlag = 1; //没有权限
    }
    return returnFlag;
}

int PowerManager::clearAllTimerRegister(UserInfo userInfo,int &returnFlag)
{
    if(disOPeratorPermission(userInfo))
    {
        robotManager->robotsMap.value(robotId)->programEngine->regData->clearAllTimerValue();
    }
    else
    {
        returnFlag = 1; //没有权限
    }
    return returnFlag;
}

int PowerManager::clearCurrentProduction(UserInfo userInfo, int &returnFlag)
{
    if(disOPeratorPermission(userInfo))
    {
        robotManager->robotsMap.value(robotId)->programEngine->regData->clearCurrentProduction();
    }
    else
    {
        returnFlag = 1; //没有权限
    }
    return returnFlag;
}

int PowerManager::clearAccumulatedProduction(UserInfo userInfo, int &returnFlag)
{
    if(disOPeratorPermission(userInfo))
    {
        robotManager->robotsMap.value(robotId)->programEngine->regData->clearAccumulatedProduction();
    }
    else
    {
        returnFlag = 1; //没有权限
    }
    return returnFlag;
}



int PowerManager::backupControllerProgram(UserInfo userInfo,std::string fileLocation,int &returnFlag){
    if(disOPeratorPermission(userInfo))
    {
            FUNTION_IS_EMPTY
    }
    else
    {
         returnFlag = 1; //没有权限
    }
    return returnFlag;
}







bool PowerManager::fileExists(QString fileName)
{
    QFile file(fileName);
    if(file.exists())
    {
        return true;
    }
    else
    {
        return false;
    }
}



QString PowerManager::ipAddress(QString network)
{
    QList<QNetworkAddressEntry> list;
   QString localIpAddress;

   QNetworkInterface interface = QNetworkInterface::interfaceFromName(network);
   list = interface.addressEntries();

   if(!list.isEmpty())
   {
       localIpAddress = list.at(0).ip().toString();
   }

   return localIpAddress;
}

QString PowerManager::macAddress(QString network)
{
    QList<QNetworkInterface> netList;

   int netCount;
   int neti;

   QNetworkInterface myNet;
   netList = QNetworkInterface::allInterfaces();
   netCount = netList.count();

   for(neti = 0; neti < netCount; neti++)
   {
       if(netList.at(neti).isValid() && (netList.at(neti).name() == network))
       {
           myNet = netList.at(neti);
           break;
       }
   }

   return (myNet.hardwareAddress());
}

void PowerManager::setIpAddress(ControllerIpGroupInfo controllerIpGroupInfo)
{
       ipFileList.clear();
       dnsFileList.clear();

       QString lineStr = "";
       QString nextLineStr = "\n";
       QString spaceStr = "  ";
       QFile file(IP_FILE);

       if(file.open(QIODevice::ReadWrite | QIODevice::Truncate))
       {
           file.reset();

           QTextStream out(&file);

//           while(!out.atEnd())
//           {
//               lineStr = out.readLine();
//               ipFileList.append(lineStr);
//           }

//           file.resize(0);

           lineStr = "auto"+ spaceStr + networkName;
           ipFileList.append(lineStr);
           lineStr = "iface" + spaceStr + networkName + "  inet static";
           ipFileList.append(lineStr);
           lineStr = "address"+ spaceStr + QString::fromStdString(controllerIpGroupInfo.ipAddress);
           ipFileList.append(lineStr);
           lineStr = "netmask" + spaceStr + "255.255.255.0";
           ipFileList.append(lineStr);
           lineStr = "gateway" + spaceStr + QString::fromStdString(controllerIpGroupInfo.gateWay);
           ipFileList.append(lineStr);

           for(int i = 0; i < ipFileList.size();i++)
           {
//               qDebug() << "******ipFileList[i]********"<<ipFileList[i]<<"\n\n\n";
               out << ipFileList[i] << "\n";
           }

           file.close();
           file.flush();//必须加，如果不加，可能关机的时候丢失文件内容。

           system("sudo /etc/init.d/networking restart");
       }
       else
       {
           //消息预留
           //打开ｉｐ地址文件失败
           qDebug() << "***open ip file error!!!!***"<<endl;
       }

       if(""== controllerIpGroupInfo.dnsServer)
       {

       }
       else
       {
           QFile dnsFile(DNS_FILE);

           if(dnsFile.open(QIODevice::ReadWrite | QIODevice::Truncate))
           {
               dnsFile.reset();

               QTextStream out(&dnsFile);

//               while(!out.atEnd())
//               {
//                   lineStr = out.readLine();
//                   dnsFileList.append(lineStr);
//               }
//               dnsFile.resize(0);

               lineStr = "nameserver"+ spaceStr + QString::fromStdString(controllerIpGroupInfo.dnsServer);
               dnsFileList.append(lineStr);

               for(int i = 0; i < dnsFileList.size();i++)
               {
                   out << dnsFileList[i] << endl;
               }

               dnsFile.close();
               dnsFile.flush();//必须加，如果不加，可能关机的时候丢失文件内容。

           }
           else
           {
               //消息预留
               //打开ｉｐ地址文件失败
               qDebug() << "***open ip file error!!!!***"<<endl;
           }
       }

       QString systemDownStr = "sudo ifconfig  " + networkName +spaceStr +"down";
       QString systemUpStr = "sudo ifconfig  " + networkName + spaceStr+ "up";

       QByteArray arrayDown = systemDownStr.toLatin1();
       char *downCmd = arrayDown.data();

       QByteArray arrayUp = systemUpStr.toLatin1();
       char *upCmd = arrayUp.data();


       system(downCmd);
       system(upCmd);
       system("sudo /etc/init.d/networking restart");
}

void PowerManager::setMacAddress(QString macAddressStr)
{
    macFileList.clear();

    QString lineStr = "";
    QString nextLineStr = "\n";
    QString spaceStr = "  ";
    QString configStr = "ifconfig";
    QString upStr = "up";
    QString downStr = "down";
    QString hwStr = "hw";
    QString etherStr = "ether";

    QString endStr = "";
    QFile file(MAC_FILE);

    if(file.open(QIODevice::ReadWrite | QIODevice::Text))
    {
        file.reset();

        QTextStream out(&file);

        while(!out.atEnd())
        {
            lineStr = out.readLine();
            macFileList.append(lineStr);
        }

        file.resize(0);

        endStr = lineStr;

        macFileList.remove(macFileList.size() - 1);

        lineStr = configStr + spaceStr + networkName + spaceStr + downStr;
        macFileList.append(lineStr);

        lineStr = configStr + spaceStr + networkName + spaceStr + hwStr
                + spaceStr + etherStr + spaceStr + macAddressStr;
        macFileList.append(lineStr);

        lineStr = configStr + spaceStr + networkName + spaceStr + upStr;
        macFileList.append(lineStr);

        macFileList.append(endStr);

        for(int i = 0; i < macFileList.size();i++)
        {
            out << macFileList[i] << endl;
        }

        file.close();
        file.flush();//必须加，如果不加，可能关机的时候丢失文件内容。
    }
    else
    {
        //消息预留
        //打开ｉｐ，ｍａｃ地址文件失败
        qDebug() << "***open ip file error!!!!***"<<endl;
    }
}

void PowerManager::readBaseData()
{
    QVariant strConfigValue;
    QString ipInfoStr = D_TCRCONTROLLER_DATA_PATH;
    ipInfoStr+=GLOBAL_BASEDATA;

    QString strConfigGroup = "";
    QString strConfigKey = "";

    QSettings settings(ipInfoStr,QSettings::IniFormat);
    settings.setIniCodec("UTF-8");
    strConfigGroup = "ipMacInfo";
    settings.beginGroup(strConfigGroup);

    strConfigKey = "ethName";
    strConfigValue = settings.value(strConfigKey);

    networkName = strConfigValue.toString();
    settings.endGroup();
}






int PowerManager::feedDog()
{
    qDebug()<<"PowerManager::feedDog2";
    watchDog->feedDog();
    return 1;
}

int PowerManager::feedDog(UserInfo userInfo, int &returnFlag)
{
    qDebug()<<"PowerManager::feedDog1";
    watchDog->feedDog();
    returnFlag=0;
    return 1;
}

int PowerManager::readStartType()
{
    return globalManager->getStartType();
}

void PowerManager::addMsg(int messageLevel, string componentName, string messageType,
                           int messageCode, int robotId,
                           int parameter1, int parameter2, int parameter3, int parameter4)
{
    Message tmpMsg;
    tmpMsg.MessageLevel = messageLevel;
    tmpMsg.componentClassName = componentName;
    tmpMsg.messageType = messageType;
    tmpMsg.robotId = robotId;
    tmpMsg.messageCode = messageCode;
   // tmpMsg.time = t1.tv_sec;


    QString infomationStr;

    switch(messageCode)
    {
    case 6030:
    {
        infomationStr =  QObject::tr("用户密码修改成功！");
        break;
    }
    case 6029:
    {
        infomationStr =  QObject::tr("hmi版本过旧，请升级新版本！");
        break;
    }
    case 6028:
    {
        infomationStr =  QObject::tr("hmi版本不兼容，禁止登录！");
        break;
    }
    case 6027:
    {
        infomationStr =  QObject::tr("初始化位置的点号%1不存在，初始化位置失败！").arg(parameter1);
        break;
    }
    case 6026:
    {
        infomationStr =  QObject::tr("可许证状态无效，不允许运行程序，请联系供应商获取新注册码并注册！");
        break;
    }
    case 6025:
    {
        infomationStr =  QObject::tr("注册码即将过期，请联系供应商获取新注册码并注册！");
        break;
    }
    case 6024:
    {
        infomationStr =  QObject::tr("注册码已经过期，请联系供应商获取新注册码并注册！");
        break;
    }
    case 6023:
    {
        infomationStr =  QObject::tr("用户强制退出了程序！");
        break;
    }
    case 6022:
    {
        infomationStr =  QObject::tr("用户信号设置了禁止了程序运行！");
        break;
    }
    case 6021:
    {
        infomationStr =  QObject::tr("机器人电机电池失效导致原点丢失！");
        break;
    }
    case 6020:
    {
        infomationStr =  QObject::tr("robotId超过合理范围！");
        break;
    }
    case 6019:
    {
        infomationStr =  QObject::tr("手动看门狗记时超过设定，可能网络异常导致！");
        break;
    }
    case 6018:
    {
        infomationStr =  QObject::tr("设备使用次数已经超过授权，请联系设备供应商注册！");
        break;
    }
    case 6017:
    {
        infomationStr =  QObject::tr("用户配置文件userInfo.xml校验错误，请联系设备供应商!");
        break;
    }
    case 6016:
    {
        infomationStr =  QObject::tr("用户配置文件userInfo.xml缺少节点数据，请联系设备供应商!");
        break;
    }
    case 6015:
    {
        infomationStr =  QObject::tr("用户配置文件userInfo.xml不存在,或者许可证文件不存在!");
        break;
    }
    case 6014:
    {
        infomationStr =  QObject::tr("设备注册码无效，请联系设备供应商注册！本机硬件序列号：")
                +authority->getHardDiskSerialNumber();
        break;
    }
    case 6013:
    {
        infomationStr =  QObject::tr("设备使用授权已经到期，请联系设备供应商注册！本机硬件序列号：")
                +authority->getHardDiskSerialNumber();
        break;
    }
    case 6012:
    {
        infomationStr =  QObject::tr("设备使用授权即将到期，请联系设备供应商注册！本机硬件序列号：")
                 +authority->getHardDiskSerialNumber();
        break;
    }
    case 6011:
    {
        infomationStr =  QObject::tr("用户配置文件userInfo.xml不存在，不允许运行!");
        break;
    }

//    case 6010:
//    {
//       infomationStr = QObject::tr("控制系统当前开机次数") +
//               QString::number(parameter1) +
//               QObject::tr("大于厂家限制") +
//               QString::number(parameter2) +
//               QObject::tr("次数，无法使用，请联系销售人员！");
//       break;
//    }

//    case 6009:
//    {
//        infomationStr =  QObject::tr("用户配置文件userInfo.xml,找不到BootCount节点!");
//        break;
//    }
//    case 6008:
//    {
//        infomationStr =  QObject::tr("用户配置文件userInfo.xml,找不到pollCode节点!");
//        break;
//    }
//    case 6007:
//    {
//        infomationStr =  QObject::tr("用户配置文件userInfo.xml,找不到Admin节点!");
//        break;
//    }
//    case 6006:
//    {
//        infomationStr =  QObject::tr("用户配置文件userInfo.xml,找不到User节点!");
//        break;
//    }
//        case 6005:
//        {
//            infomationStr =  QObject::tr("无法打开用户配置文件userInfo.xml,请联系厂家解决!");
//            break;
//        }
        case 6000:
        {
            infomationStr =  QObject::tr("机器人程序正在运行，再次发送运行指令无效！");

        }
        break;
        case 6001:
        {
            infomationStr =  QObject::tr("用户权限不足！");
            break;
        }
        break;
        case 6002:
        {
            infomationStr =  QObject::tr("紧急停止按钮按下!");
            break;
        }       
        break;
        case 6003:
        {
            infomationStr =  QObject::tr("管理员原有密码不正确，请重新输入!");
        }
        break;

        case 1001:
        {
            infomationStr =  QObject::tr("系统正在初始化，请耐心等待－－－－－－－!");
        }
        break;
    }


    tmpMsg.MessageInformation = infomationStr.toStdString();

    // qDebug()<<"53444444444444444444444"<< tmpMsg.messageCode;
    MessageLog::getInstance()->addMessage(tmpMsg);
}

//int PowerManager::writeStartTypeToFile(int writeStartType)
//{
//   return globalManager->writeStartTypeToFile(writeStartType);
//}



int PowerManager::connectVrep(UserInfo userInfo,std::string ip,int port,int &returnFlag){
    //  int ret=vrepControl->connectToVrep(ui->lineEdit_ip->text(), ui->spinBox_vrep_port->value() );
    if(disOPeratorPermission(userInfo))
    {
            FUNTION_IS_EMPTY
    }
    else
    {
         returnFlag = 1; //没有权限
    }
    return returnFlag;
}

int PowerManager::disconnectVrep(UserInfo userInfo,int &returnFlag){
    if(disOPeratorPermission(userInfo))
    {
            FUNTION_IS_EMPTY
    }
    else
    {
         returnFlag = 1; //没有权限
    }
    return returnFlag;
}

int PowerManager::setVrepServoType(UserInfo userInfo,int type,int &returnFlag){
    if(disOPeratorPermission(userInfo))
    {
            FUNTION_IS_EMPTY
    }
    else
    {
         returnFlag = 1; //没有权限
    }
    return returnFlag;
}

int PowerManager::setVrepIoType(UserInfo userInfo,int type,int &returnFlag){
    if(disOPeratorPermission(userInfo))
    {
            FUNTION_IS_EMPTY
    }
    else
    {
         returnFlag = 1; //没有权限
    }
    return returnFlag;
}


int PowerManager::setBrake( UserInfo userInfo ,int type, int &returnFlag )
{
    if(disOPeratorPermission(userInfo))
    {
          //  FUNTION_IS_EMPTY
        qDebug() << "*******************-----------------------------------------setBrake:type=" << type;
        LONG64 dataReturn;
        int returnLen = 2;
        for (int i = 0; i < robotManager->robotsInfoMap[1]->robotMotorCount; i++)
        {
            robCtl->setSdo(1, i, 0x3711, 0, type, returnLen);
            robCtl->getSdo(1, i, 0x3711, 0, dataReturn, returnLen);
            qDebug() << "----------------///////////axis:" << i << "-------brake------0x3711:" << dataReturn;
        }
    }
    else
    {
         returnFlag = 1; //没有权限
    }
    return returnFlag;
}






